-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
146 lines (146 loc) · 4.07 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
const path = require('path');
const glob = require('glob');
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin');
// const WebpackMd5Hash = require('webpack-md5-hash');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const {WebpackManifestPlugin} = require('webpack-manifest-plugin');
const TerserPlugin = require("terser-webpack-plugin");
// Create an interface to glob https://github.com/isaacs/node-glob
// https://stackoverflow.com/questions/32874025/how-to-add-wildcard-mapping-in-entry-of-webpack/34545812#34545812
const stylesForPages = pattern => glob.sync(pattern);
module.exports = (env, argv) => ({
resolve: {
// Fixes for using EJS client side
alias: {
fs: false,
path: false
}
},
entry: {
app: ['./src/main.js', './_scss/main.scss', ...stylesForPages('./_scss/_pages/*.scss')]
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
// exclude: ["app"],
extractComments: {
condition: /^\**!|@preserve|@license|@cc_on/i,
filename: (fileData) => {
// The "fileData" argument contains object with "filename", "basename", "query" and "hash"
return `LICENSE.txt${fileData.query}`;
},
banner: (licenseFile) => {
return `License information can be found in ${licenseFile}`;
},
},
terserOptions: {
ecma: undefined,
parse: {},
compress: {},
mangle: {
properties: false,
reserved: [
"i18next",
"emitter",
"rws",
"loader",
"renderer",
"actions",
"todos",
"filter",
"locale",
"reducers",
"configuration",
"store",
"head",
"input",
"list",
"foot"
]
}
}
})
],
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendor',
chunks: 'all'
}
}
}
},
devtool: argv.mode === 'production' ? false : 'source-map',
output: {
path: path.resolve(__dirname, 'dist'),
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
// This is structure for compiling scss into css and placing it into the dist directory
// It is a departure from typical thinking of including css inside javascript to facilitate
// runtime loading of modules with their supporting styles as one would with React,
// Angular or Vue where that is the norm.
{
test: /\.scss$/,
exclude: /node_modules/,
use: [
{
loader: 'file-loader',
options: { outputPath: 'css/', name: '[name].min.css'}
},
{
loader: 'sass-loader',
options: {
// Use Dart SASS
implementation: require('sass'),
outputStyle: 'compressed'
}
}
]
}
]
},
plugins: [
new CleanWebpackPlugin('dist', {}),
new CopyWebpackPlugin([
{from: './_assets', to: './'}
]),
new HtmlWebpackPlugin({
inject: true,
chunks: ['vendor', 'app'],
hash: true,
template: './_templates/index.html',
filename: 'index.html'
}),
new CompressionPlugin({
algorithm: 'gzip',
test: /\.js(\?.*)?$/i
}),
new WebpackManifestPlugin(),
new webpack.ProvidePlugin({
_: 'lodash',
$: 'jquery',
jQuery: 'jquery',
i18next: 'i18next', // <= this does not seem to work, I still have to use => window['i18next'] = i18next;
ejs: 'ejs'
})
],
// TODO This is not setup yet
devServer: {
contentBase: 'dist',
watchContentBase: true,
port: 1000
}
});