1 | const path = require('path');
|
2 |
|
3 | const baseBuildOptions = {
|
4 | entry: { type: 'string', description: 'entry file path', default: './src/index.js' },
|
5 | outputPath: { type: 'string', description: 'build path', default: './build/' },
|
6 | browsers: {
|
7 | type: 'string',
|
8 | description: 'target browsers',
|
9 | default: '>= 1%, not ie < 9, not chrome < 40, not safari < 8, not iOS < 8, not Android < 40',
|
10 | },
|
11 | publicPath: { type: 'string', description: 'webpack publicPath', default: '' },
|
12 | babelrc: { type: 'boolean', description: 'babel-loader respect .babelrc', default: false },
|
13 | cssModules: { type: 'boolean', description: 'enable css modules', default: false },
|
14 | };
|
15 |
|
16 | module.exports = ({
|
17 | commands: {
|
18 | build: {
|
19 | default: 'prod',
|
20 | dev: [
|
21 | Object.assign({}, baseBuildOptions, {
|
22 | profile: { type: 'boolean', description: 'output webpack profile', default: false },
|
23 | }),
|
24 | [
|
25 | ['file', ({ options }) => ({ type: 'empty', from: options.outputPath })],
|
26 | ['webpack', path.resolve(__dirname, './webpack/dev.build.js')],
|
27 | ],
|
28 | '开发环境构建',
|
29 | ],
|
30 | prod: [
|
31 | Object.assign({}, baseBuildOptions, {
|
32 | supportIE8: { type: 'boolean', description: 'minify support ie8', default: false },
|
33 | compileNodeModules: { type: 'boolean', description: 'compile js files in node_modules', default: true },
|
34 | profile: { type: 'boolean', description: 'output webpack profile', default: false },
|
35 | }),
|
36 | [
|
37 | ['file', ({ options }) => ({ type: 'empty', from: options.outputPath })],
|
38 | ['webpack', path.resolve(__dirname, './webpack/prod.js')],
|
39 | ],
|
40 | '生产环境构建',
|
41 | ],
|
42 | },
|
43 | server: [
|
44 | Object.assign({}, baseBuildOptions, {
|
45 | port: { type: 'number', description: 'server port', default: 8080 },
|
46 | hot: { type: 'boolean', description: 'enable hotModuleReplacement', default: false },
|
47 | }),
|
48 | [['webpack', path.resolve(__dirname, './webpack/dev.server.js')]],
|
49 | '启动开发服务器',
|
50 | ],
|
51 | },
|
52 | help: {
|
53 | build: {
|
54 | _label: '构建项目',
|
55 | _default: 'prod',
|
56 | dev: '开发环境构建',
|
57 | prod: '生产环境构建',
|
58 | },
|
59 | server: '启动开发服务器',
|
60 | },
|
61 | });
|