-
Notifications
You must be signed in to change notification settings - Fork 54
/
webpack.config.js
122 lines (113 loc) · 3.85 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
// webpack.config.js
var webpack = require('webpack');
var path = require('path');
var fs = require('fs');
const { profileEnd } = require('console');
process.traceDeprecation = true;
function config(nodeEnv) {
return {
devtool: 'inline-source-map',
resolve: {
extensions: ['.webpack.js', '.web.js', '.js', '.ts', '.tsx']
},
entry: {
bigRenderTest: ['./src/ts/bigRenderTest.tsx'],
renderTest: ['./src/ts/renderTest.tsx'],
prefsPage: ['./src/ts/prefsPage.tsx'],
tabliPopup: ['./src/ts/tabliPopup.ts'],
tabliPopout: ['./src/ts/tabliPopout.ts'],
bgHelper: ['./src/ts/bgHelper.ts']
},
output: {
path: __dirname + '/build/js',
filename: '[name].bundle.js'
},
module: {
rules: [
// { test: /\.(json)$/, loader: 'raw-loader' },
// All files with a '.ts' or '.tsx' extension will be handled by 'ts-loader'.
{ test: /\.tsx?$/, loader: 'ts-loader' },
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
{ enforce: 'pre', test: /\.js$/, loader: 'source-map-loader' },
{
test: /\.less$/,
use: ['style-loader', 'css-loader', 'less-loader' ]
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader' ]
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
type: 'asset'
/* loaders: [
'file-loader?hash=sha512&digest=hex&name=[hash].[ext]',
'image-webpack-loader?bypassOnDebug&optipng.optimizationLevel=7&gifsicle.interlaced=false'
]
*/
},
{
test: /\.(eot|svg|ttf|woff|woff2)$/,
type: 'asset'
/* loader: 'file-loader?name=public/fonts/[name].[ext]' */
},
{ test: /\.html$/, loader: 'html-loader' }
]
},
optimization: {
splitChunks: {
name: 'common',
chunks: 'initial',
minChunks: 2
// (the commons chunk name)
// filename: "common.js",
// (the filename of the commons chunk)
}
},
// When importing a module whose path matches one of the following, just
// assume a corresponding global variable exists and use that instead.
// This is important because it allows us to avoid bundling all of our
// dependencies, which allows browsers to cache those libraries between builds.
externals: {
// react: 'React',
// 'react-dom': 'ReactDOM'
},
plugins: []
};
}
function development() {
var dev = config('development');
Object.assign(dev.optimization, {
minimize: false
});
return dev;
}
function production() {
var prod = config('production');
prod.plugins.push(
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
})
);
prod.optimization.chunkIds = 'total-size';
prod.optimization.minimize = true;
// for profiling:
/*
prod.optimization.minimize = false; // avoids mangling
prod.resolve.alias = {
'react-dom$': 'react-dom/profiling',
'scheduler/tracing': 'scheduler/tracing-profiling'
};
console.log('profuction config: ', prod);
*/
return prod;
}
const configMap = {
dev: development(),
prod: production()
};
module.exports = function(env, argv) {
let mode = (argv.mode === 'production') ? 'prod' : 'dev';
let ret = configMap[mode];
return ret;
};