-
Notifications
You must be signed in to change notification settings - Fork 12
/
webpack.config.js
104 lines (98 loc) · 2.34 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
var path = require("path");
var webpack = require('webpack');
var fs = require("fs");
var AssetsPlugin = require('assets-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const reactSrcDir = '/assets/react';
// TODO clean bundles when generating new ones
function getReactChunks(){
// Add all jsx files in /assets/react as entries
var files = fs.readdirSync(__dirname + reactSrcDir).filter(function(f){
return f.endsWith('.jsx') || f.endsWith('.js');
})
var entries = {};
files.forEach(function(f){
entries[f.replace(/\.(jsx|js)$/, '')] = './' + f;
});
return entries;
}
const reactBuild = {
name: 'react',
context: __dirname + reactSrcDir,
entry: getReactChunks(),
output: {
path: path.resolve('./assets/bundles/'),
filename: "[name]-[hash].js",
assetModuleFilename: '[name]-[hash][ext][query]',
publicPath: '/assets/bundles/',
clean: false,
},
devtool: 'source-map',
module: {
rules: [
{
test: /\.(css|sass|scss)$/,
use: [
{ loader: MiniCssExtractPlugin.loader},
{ loader: 'css-loader' },
{ loader: 'resolve-url-loader' },
{
loader: 'sass-loader',
options: {
sourceMap: true,
}
}
]
},
{
test: /\.(jsx|js)$/,
exclude: /node_modules/,
use: [
{ loader: 'babel-loader' }
]
},
{
test: /\.woff2?$|\.ttf$|\.eot$|\.svg$|\.png$|\.gif$/,
type: 'asset/resource',
},
],
},
externals: {
jquery: 'jQuery',
$: 'jQuery'
},
optimization: {
//runtimeChunk: "single", // enable "runtime" chunk
splitChunks: {
cacheGroups: {
common: {
name: 'common',
chunks: 'initial',
minChunks: 3
}
}
},
},
plugins: [
new MiniCssExtractPlugin({
filename: "[name]-[hash].css",
chunkFilename: "[id].css",
}),
new webpack.IgnorePlugin({
resourceRegExp: /^\.\/locale$/,
contextRegExp: /moment$/
}),
new AssetsPlugin({
filename: 'bundles.json',
path: path.resolve('./_data'),
})
],
resolve: {
modules: [
path.resolve('./assets/react/'),
'node_modules'
],
extensions: ['.js', '.jsx', '.css'],
}
};
module.exports = [reactBuild]