-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
92 lines (88 loc) · 2.47 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
/* eslint-disable require-jsdoc */
const path = require('path')
const DefinePlugin = require('webpack/lib/DefinePlugin')
const CleanObsoleteChunks = require('webpack-clean-obsolete-chunks')
const ManifestPlugin = require('webpack-manifest-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const TerserPlugin = require('terser-webpack-plugin')
const _resolve = (...args) => path.resolve(__dirname, ...args)
class LoggerPlugin {
apply(compiler) {
const timestamp = () => `[${(new Date()).toLocaleString()}]`
compiler.plugin('compile', (params) => {
console.log('\x1b[1;36m' + '================================')
console.log(timestamp() + ' Start compile' + '\x1b[0m')
})
compiler.plugin('after-emit', (params, callback) => {
callback()
console.log('\x1b[1;35m' + timestamp() + ' Finish compile')
console.log('================================' + '\x1b[0m')
})
}
}
const SOURCE_DIR = _resolve('./circle_core/web/src')
const DEST_DIR = _resolve('./circle_core/web/static')
module.exports = (env, argv) => ({
context: _resolve(SOURCE_DIR, 'js'),
entry: {
main: ['@babel/polyfill', `${SOURCE_DIR}/js/main.jsx`],
public: ['@babel/polyfill', `${SOURCE_DIR}/js/public.jsx`],
},
output: {
path: DEST_DIR,
filename: '[name].[chunkhash].js'
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
cacheDirectory: true,
},
},
{
test: /\.css$/,
loader: 'ignore-loader'
}
],
},
devtool: (argv && argv.mode == 'production') ? false : 'cheap-module-eval-source-map',
resolve: {
alias: {
'src': _resolve(SOURCE_DIR, 'js')
},
modules: ['node_modules'],
extensions: ['.jsx', '.js'],
},
plugins: [
new CopyWebpackPlugin([
{
from: _resolve(SOURCE_DIR, 'images'),
},
]),
new LoggerPlugin(),
new ManifestPlugin(),
new CleanObsoleteChunks({verbose: true, deep: true}),
],
target: 'web',
...((argv && argv.mode != 'production') ? {} : {
optimization: {
// `$super`をmangleしないように
// https://github.com/shutterstock/rickshaw#minification
minimizer: [
new TerserPlugin({
cache: true,
parallel: true,
sourceMap: false,
terserOptions: {
mangle: {
reserved: ['$super'],
}
}
})
]
}
})
})