-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
124 lines (120 loc) · 4.2 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
const fs = require('fs-extra');
const path = require('path');
// const forever = require('forever-monitor');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
module.exports = () => {
/** 当前是否是开发环境 */
const isEnvDevelopment = process.env.WEBPACK_BUILD_ENV === 'dev';
/** 打包结果路径 */
const dist = isEnvDevelopment
? path.resolve(__dirname, '.dev')
: path.resolve(__dirname, 'bin');
const config = {
mode: isEnvDevelopment ? 'development' : 'production',
devtool: isEnvDevelopment ? 'cheap-module-source-map' : 'source-map',
target: 'async-node',
watch: isEnvDevelopment ? true : false,
output: {
filename: '[name].js',
path: dist
},
plugins: [],
entry: {
_inquirer: [path.resolve(__dirname, 'src/_inquirer.ts')],
dev: [path.resolve(__dirname, 'src/dev.ts')]
},
module: {
rules: [
{
test: /\.(js|mjs|cjs|ts)$/,
use: {
loader: 'babel-loader',
options: {
cwd: __dirname,
cacheDirectory: true,
presets: [
[
'@babel/preset-env',
{
modules: false,
exclude: [
'@babel/plugin-transform-regenerator',
'@babel/plugin-transform-async-to-generator'
]
}
],
'@babel/preset-typescript'
],
compact: 'auto'
}
}
}
]
},
// optimization: {
// splitChunks: false,
// removeAvailableModules: false,
// removeEmptyChunks: false,
// mergeDuplicateChunks: false,
// occurrenceOrder: false,
// concatenateModules: false
// },
resolve: {
modules: ['__modules', 'node_modules'],
extensions: ['.js', '.ts', '.mjs', '.cjs']
},
stats: {
all: false,
modules: true,
maxModules: 0,
errors: true,
warnings: true,
moduleTrace: true,
errorDetails: true,
performance: true
},
performance: {
maxEntrypointSize: 100 * 1024 * 1024,
maxAssetSize: 100 * 1024 * 1024
},
node: { __dirname: false }
// externals: {
// inquirer: 'commonjs inquirer'
// }
};
if (!isEnvDevelopment) {
config.plugins.push(new CleanWebpackPlugin());
} else {
const exitHandler = async (...args) => {
await fs.remove(dist);
};
process.on('exit', exitHandler);
process.on('SIGINT', exitHandler);
process.on('SIGUSR1', exitHandler);
process.on('SIGUSR2', exitHandler);
process.on('uncaughtException', exitHandler);
// let child;
// config.plugins.push({
// apply: compiler => {
// compiler.hooks.watchRun.tap('ApiServerPlugin', compilation => {
// if (child) {
// child.stop();
// } else {
// child = new forever.Monitor(
// path.resolve(dist, 'run.js'),
// {
// max: 1,
// silent: false,
// killTree: true
// }
// );
// }
// });
// compiler.hooks.afterEmit.tap('ApiServerPlugin', compilation => {
// child.start();
// });
// }
// });
}
return config;
};