-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
80 lines (72 loc) · 1.76 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
/* eslint-disable */
var webpack = require('webpack'),
TerserPlugin = require('terser-webpack-plugin'),
WriteFilePlugin = require('write-file-webpack-plugin'),
path = require('path');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const NODE_ENV = process.env.NODE_ENV || 'production';
var isDev = 'development' === NODE_ENV || 0;
var options = {
mode: NODE_ENV,
entry: {
index: path.join(__dirname, 'src', 'index.ts'),
},
output: {
path: path.join(__dirname, 'bin'),
filename: '[name].bundle.js'
},
module: {
rules: [
{
test: /\.(ts|tsx)$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
{
test: /\.css$/,
use: [
'style-loader',
'css-loader',
],
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
loader: 'file-loader'
},
],
},
resolve: {
alias: {},
extensions: ['.tsx', '.jsx', '.ts', '.js', '.json'],
},
plugins: [
// clean the web folder
new CleanWebpackPlugin(),
// expose and write the allowed env vars on the compiled bundle
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(NODE_ENV),
}),
new WriteFilePlugin()
],
};
if (isDev) {
options.devtool = 'source-map';
} else {
options.optimization = {
minimize: true,
minimizer: [new TerserPlugin()],
};
}
options.plugins.push(function () {
this.hooks.done.tapAsync('done', function (stats, callback) {
if (0 < stats.compilation.errors.length) {
console.log('\x1b[31m%s\x1b[0m', stats.compilation.errors);
// to error out and discontinue any sequential scripts.
process.exit(1);
} else {
callback();
process.exit(0);
}
});
});
module.exports = options;