-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.prod.js
176 lines (165 loc) · 5.44 KB
/
webpack.config.prod.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
const path = require('path');
const webpack = require('webpack');
const nodeExternals = require('webpack-node-externals');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const TerserJSPlugin = require('terser-webpack-plugin');
const incstr = require('incstr');
const CssoWebpackPlugin = require('csso-webpack-plugin').default;
// const PurgecssPlugin = require('purgecss-webpack-plugin');
// const glob = require('glob')
const pkg = require('./package.json');
// const PATHS = {
// src: path.join(__dirname, 'src')
// }
const createUniqueIdGenerator = () => {
const index = {};
const generateNextId = incstr.idGenerator({
// Removed "d" letter to avoid accidental "ad" construct.
// @see https://medium.com/@mbrevda/just-make-sure-ad-isnt-being-used-as-a-class-name-prefix-or-you-might-suffer-the-wrath-of-the-558d65502793
alphabet: 'abcefghijklmnopqrstuvwxyz0123456789'
});
return (name) => {
if (index[name]) {
return index[name];
}
let nextId;
do {
// Class name cannot start with a number.
nextId = generateNextId();
} while (/^[0-9]/.test(nextId));
index[name] = generateNextId();
return index[name];
};
};
const uniqueIdGenerator = createUniqueIdGenerator();
const generateScopedName = localName => uniqueIdGenerator(localName);
module.exports = [
// NOTE: PRODUCTION_SERVER FILES
{
name: 'PRODUCTION_SERVER',
mode: 'production',
target: 'node',
node: {
__dirname: false
},
entry: {
server: ['./server/server.js']
},
output: {
path: path.join(__dirname, 'dist'),
filename: `${pkg.name}.[name].js`
},
externals: [nodeExternals()],
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: ['babel-loader']
},
{
test: /\.(le|c)ss$/,
exclude: /node_modules/,
loader: ExtractTextPlugin.extract(
[
{
loader: 'css-loader',
options: {
importLoaders: 1, // allows you to configure how many loaders before css-loader
modules: {
getLocalIdent: (context, localIdentName, localName) => generateScopedName(localName),
}
}
},
'less-loader'
]
)
}
]
},
optimization: {
minimizer: [
new TerserJSPlugin({
terserOptions: {
output: {
comments: false,
},
},
extractComments: false,
}),
]
},
plugins: [
new ExtractTextPlugin(`${pkg.name}.${pkg.version}.min.css`),
]
},
// NOTE: PRODUCTION_CLIENT FILES
{
name: 'PRODUCTION_CLIENT',
mode: 'production',
target: 'web',
node: {
__dirname: false
},
entry: {
client: [
// 'babel-polyfill',
'./src/js/index.js'
]
},
output: {
path: path.join(__dirname, 'dist'),
filename: `${pkg.name}.${pkg.version}.min.js`,
chunkFilename: `[id].${pkg.version}.client.min.js`
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: ['babel-loader']
},
{
test: /\.(le|c)ss$/,
exclude: /node_modules/,
loader: ExtractTextPlugin.extract(
[
{
loader: 'css-loader',
options: {
importLoaders: 1,
modules: {
getLocalIdent: (context, localIdentName, localName) => generateScopedName(localName),
}
}
},
'less-loader'
]
)
}
]
},
optimization: {
minimizer: [
new TerserJSPlugin({
terserOptions: {
output: {
comments: false,
},
},
extractComments: false,
}),
]
},
plugins: [
new ExtractTextPlugin(`${pkg.name}.${pkg.version}.min.css`),
new CssoWebpackPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
// }),
// new PurgecssPlugin({
// paths: glob.sync(`${PATHS.src}/**/*`, { nodir: true })
})
]
}
];