我们经常会遇到单独对 JS 打包的场景,比如 es6 写的 npm 包需要构建成 es5 模式. easywebpack 也提供了对应的解决方案: easywebpack-js
基于 easywebpack-js 构建
- 配置编写
// build/index.js
const easywebpack = require('easywebpack-js');
const config = {
env: process.env.BUILD_ENV,
entry: {
index: 'lib/index.js'
}
};
easywebpack.build(config);
- 命令行配置构建
// ${app_root}/package.json
{
"scripts": {
"build:test": "cross-env BUILD_ENV=test NODE_ENV=development node build/index.js",
"build:prod": "cross-env BUILD_ENV=prod NODE_ENV=production node build/index.js",
}
}
基于 easywebpack-cli 构建
// ${app_root}/webpack.config.js
const easywebpack = require('easywebpack-js');
module.exports = {
framework: 'js',
entry: {
'index': 'lib/index.js'
}
};
- 命令行配置构建
// ${app_root}/package.json
{
"scripts": {
"build:test": "easy build test",
"build:prod": "easy build prod",
}
}
基于 Webpack 构建
// ${app_root}/webpack.config.js
const easywebpack = require('easywebpack-js');
const config = {
env: process.env.BUILD_ENV,
framework: 'js',
entry: {
'index': 'lib/index.js'
}
};
module.exports = easywebpack.getWebpackConfig(config);
- 命令行配置构建
// ${app_root}/package.json
{
"scripts": {
"build:test": "cross-env BUILD_ENV=test webapck --config webpack.config.js",
"build:prod": "cross-env BUILD_ENV=prod webapck --config webpack.config.js",
}
}