-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.production.admin.js
executable file
·137 lines (133 loc) · 3.97 KB
/
webpack.config.production.admin.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
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const ManifestPlugin = require('webpack-manifest-plugin');
const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin');
const webpack = require('webpack');
const path = require('path');
module.exports = {
entry: ['@babel/polyfill', './src/modules/administration/index.js'],
devtool: 'source-map',
mode: 'production',
node: {
fs: 'empty',
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
{
test: /\.html$/,
use: {
loader: 'html-loader',
},
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(png|svg|jpg|gif)/,
use: 'file-loader',
},
{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'fonts/',
},
},
],
},
],
},
output: {
filename: '[name].[hash].js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/',
},
optimization: {
minimize: true,
nodeEnv: 'staging',
runtimeChunk: 'single',
splitChunks: {
chunks: 'all',
maxInitialRequests: Infinity,
minSize: 0,
// cacheGroups: {
// vendor: {
// test: /[\\/]node_modules[\\/]/,
// name(module) {
// // get the name. E.g. node_modules/packageName/not/this/part.js
// // or node_modules/packageName
// const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
//
// // npm package names are URL-safe, but some servers don't like @ symbols
// return `npm.${packageName.replace('@', '')}`;
// }
// }
// }
},
},
plugins: [
new SWPrecacheWebpackPlugin({
// By default, a cache-busting query parameter is appended to requests
// used to populate the caches, to ensure the responses are fresh.
// If a URL is already hashed by Webpack, then there is no concern
// about it being stale, and the cache-busting can be skipped.
dontCacheBustUrlsMatching: /\.\w{8}\./,
filename: 'precache-service-worker.js',
logger(message) {
if (message.indexOf('Total precache size is') === 0) {
// This message occurs for every build and is a bit too noisy.
return;
}
console.log(message);
},
minify: true, // minify and uglify the script
navigateFallback: './index.html',
staticFileGlobsIgnorePatterns: [/\.map$/, /asset-manifest\.json$/],
}),
new CopyPlugin([
{ from: './src/assets', to: 'assets' },
{ from: './src/service-workers', to: 'service-workers' },
{ from: './src/.htaccess' },
{ from: './src/.conf' },
{ from: './src/robots.txt' },
]),
new ManifestPlugin({
fileName: 'asset-manifest.json',
}),
new HtmlWebpackPlugin({
template: './src/index.html',
filename: './index.html',
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
},
}),
],
resolve: {
alias: {
Images: path.resolve(__dirname, 'src/assets/images'),
SharedComponents: path.resolve(__dirname, 'src/components'),
Config: path.resolve(__dirname, 'src/config'),
Utils: path.resolve(__dirname, 'src/utils'),
Fonts: path.resolve(__dirname, 'src/assets/fonts'),
Src: path.resolve(__dirname, 'src'),
Modules: path.resolve(__dirname, 'src/modules'),
Layouts: path.resolve(__dirname, 'src/layouts'),
Root: path.resolve(__dirname, ''),
},
},
target: 'web',
};
// https://hackernoon.com/the-100-correct-way-to-split-your-chunks-with-webpack-f8a9df5b7758