[Javascript] An Introduction to JSPM (JavaScript Package Manager)

本文介绍如何利用JSPM安装依赖包、编写ES6应用,并将其打包为生产环境可用的文件。通过简单的步骤,从安装JSPM到创建并运行一个使用ES6特性的应用,最后将应用打包成单个文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

JSPM can handle installed packages, transpiling ES6, and bundling all from the command-line. This video gives a quick overview of install JSPM, installing packages with JSPM, writing a very simple app in ES6 that uses those packages, then bundling up for production.

 

Install:

npm install jspm -g

 

You can use jspm to install any package:

jspm install --save lodash moment

 

This will help you to create package.json and you need to select some default options such as transplier: Babel.

 

We create index.html, to import system.js and config.js files whcih created by jspm. Then use System.js to import the app.js file.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="./jspm_packages/system.js"></script>
    <script src="config.js"></script>
    <script>
        System.import('app');
    </script>
</head>
<body>


</body>
</html>

 

app.js:

import moment from 'moment';
import _ from 'lodash';

let date = moment().format();

_.forEach(date, char => console.log(char));

In the file we can use ES6 already.

 

Then when you open the index.html you will see it works.

 

RUN:

jspm bundle-sfx --minify app

This will create a build.js file,

 

Replace html with:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="build.js"></script>
</head>
<body>


</body>
</html>

Only includes new build.js file, u will see everything still works.

 

转载于:https://www.cnblogs.com/Answer1215/p/4842904.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值