简介
@alib/build-scripts 是一个构建工具集,包含多个插件,可以帮助前端开发者快速构建前端项目。@alib/build-scripts 已经在阿里巴巴内部广泛使用,在性能、体验等方面有较好的表现,值得尝试。
安装
使用 npm 安装:
npm install @alib/build-scripts --save-dev
快速上手
安装完成后,在项目的 package.json
中添加如下配置:
{ "name": "my-project", "scripts": { "start": "build-scripts start", "build": "build-scripts build" } }
然后在项目的根目录下创建 src/index.js
文件。在文件中添加如下代码:
console.log('Hello world!');
现在,在命令行中运行如下命令:
npm run start
在浏览器中打开 http://localhost:4444
,你将会看到 Hello world!
的输出。
到这里,你已经完成了 @alib/build-scripts
的快速上手。接下来,我们将逐步深入了解这个构建工具集。
命令
start
build-scripts start
使用 build-scripts start
命令启动开发服务器。在开发服务器中,你的代码将会实时编译并且重新加载。这是一个非常方便的功能,因为你无需手动编译代码或者手动刷新页面。
build
build-scripts build
使用 build-scripts build
命令对代码进行构建,结果保存在 build
目录中。
配置文件
@alib/build-scripts 的配置文件是 build.json
。
下面我们来了解一些常用的配置项。
entry
entry
配置项指定入口文件。例如:
{ "entry": "src/index.js" }
这将会将 src/index.js
作为入口文件进行编译
来源:JavaScript中文网 ,转载请注明来源 https://www.javascriptcn.com/post/5eedab49b5cbfe1ea06106e4