-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwriteWebpack.js
75 lines (67 loc) · 1.82 KB
/
writeWebpack.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
const fs = require('fs');
const contentBaseUrlKey = {
'1.0.0': 'contentBase',
'1.0.1': 'contentBase',
'1.0.2': 'static'
}
const getWebpackConfig = (isTypeSciprt, version) => {
const contentBaseUrl = version
return `
const HtmlWebpackPlugin = require('html-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const path = require('path');
const isDev = process.env.NODE_ENV === 'development';
const config = {
mode: process.env.NODE_ENV,
devtool: isDev ? 'eval' : 'source-map',
entry: {
app: './src/index.${isTypeSciprt ? 'tsx' : 'jsx'}',
},
resolve: {
extensions: ${isTypeSciprt ? "['.jsx', '.js', '.tsx', '.ts']" : "['.jsx', '.js']"},
modules: [path.resolve(__dirname, './src'), 'node_modules'],
symlinks: false,
},
module: {
rules: [
{
test: ${isTypeSciprt ? /\.(js|jsx|ts|tsx)$/ : /\.(js|jsx)$/},
use: ['babel-loader'],
exclude: [/node_modules/],
}
],
},
plugins: [
new HtmlWebpackPlugin({
template: './src/index.html',
filename: 'index.html',
}),
new TerserPlugin({
parallel: true,
terserOptions: {
warnings: false,
compress: {
warnings: false,
},
ecma: 6,
mangle: true,
},
}),
],
output: {
filename: 'app.js',
path: path.join(__dirname, 'build'),
},
devServer: {
${contentBaseUrlKey[version]}: path.join(__dirname, 'build'),
historyApiFallback: true,
compress: true,
port: 9000,
},
};
module.exports = config;
`
};
module.exports.writeWebpack = function (projectName, isTypeSciprt, version) {
fs.writeFileSync(`./${projectName}/webpack.config.js`, getWebpackConfig(isTypeSciprt, version), 'utf8');
}