-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
83 lines (81 loc) · 2.23 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
const CopyPlugin = require('copy-webpack-plugin');
const MiniCSSExtractPlugin = require('mini-css-extract-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin');
const ManifestPlugin = require('webpack-manifest-plugin');
const ENV = process.env.NODE_ENV || 'development';
const DEV = ENV === 'development';
module.exports = {
entry: {
app: ['./client/index.js', './assets/styles/main.scss'],
},
output: {
path: __dirname + '/dist',
filename: `js/[name]${!DEV ? '.[contenthash]' : ''}.js`,
},
resolve: {
alias: {
// hyperhtml/cjs is returned by hypermorphic
// so that aliasing viperhtml as hyperhtml/cjs
// will basically nullify viperhtml require
viperhtml: 'hyperhtml/cjs',
},
},
optimization: {
minimizer: [new TerserPlugin({ sourceMap: true }), new OptimizeCSSPlugin()],
},
module: {
rules: [
{
test: /\.woff(2)?$/,
use: {
loader: 'file-loader',
options: {
name: `[name]${!DEV ? '.[contenthash]' : ''}.[ext]`,
outputPath: 'fonts',
publicPath: '../fonts',
},
},
},
{
test: /\.scss$/,
use: [
{ loader: MiniCSSExtractPlugin.loader },
'css-loader',
'sass-loader',
],
},
],
},
plugins: [
new MiniCSSExtractPlugin({
filename: `css/[name]${!DEV ? '.[contenthash]' : ''}.css`,
}),
new CopyPlugin([
{
from: 'public/*',
to: `${__dirname}/dist/[name]${!DEV ? '.[contenthash]' : ''}.[ext]`,
},
{
from: 'public/img/*',
to: `${__dirname}/dist/img/[name]${!DEV ? '.[contenthash]' : ''}.[ext]`,
},
]),
new ManifestPlugin({
fileName: 'assets.json',
// Remove for christmas
// https://github.com/webpack-contrib/copy-webpack-plugin/issues/104
map: file => {
if (file.isModuleAsset) {
file.name = file.path.replace(/(\.[a-f0-9]{32})(\..*)$/, '$2');
}
if (!DEV) {
file.name = file.name.replace(/(\.[a-f0-9]{32})(\..*)$/, '$2');
}
return file;
},
}),
],
devtool: 'source-map',
mode: ENV,
};