-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
136 lines (133 loc) · 3.86 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
const path = require("path");
const CleanWebpackPlugin = require("clean-webpack-plugin");
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const ResourceHintWebpackPlugin = require("resource-hints-webpack-plugin");
const ScriptExtHtmlWebpackPlugin = require("script-ext-html-webpack-plugin");
const SubresourceIntegrityWebpackPlugin = require("webpack-subresource-integrity");
const ManifestPlugin = require("webpack-manifest-plugin");
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
const outputPath = "build";
const isProd = ({ mode }) => mode === "production";
module.exports = (_env, options) => ({
entry: {
main: "./src/index.js"
},
output: {
filename: "bundle.js",
path: path.resolve(__dirname, outputPath),
crossOriginLoading: "anonymous"
},
optimization: {
minimizer: [
new UglifyJsPlugin({
cache: true,
parallel: true
}),
new OptimizeCSSAssetsPlugin({
cssProcessorOptions: {
safe: true
}
})
],
moduleIds: isProd(options) ? "size" : "named",
splitChunks: {
chunks: "all",
cacheGroups: {
styles: {
name: "styles",
test: /\.(css)$/,
chunks: "all",
enforce: true
},
react: {
name: "react",
test: /[\\/]node_modules\/(react|react-dom)[\\/]/,
chunks: "all",
priority: -5
},
purs: {
name: "purs",
test: /[\\/]output[\\/]/,
minChunks: 2,
priority: -5
},
default: {
minChunks: 2,
priority: -20
}
}
}
},
plugins: [
new CleanWebpackPlugin(["build"]),
new MiniCssExtractPlugin({
filename: "styles.css"
}),
new HtmlWebpackPlugin({
template: "src/index.html"
}),
new ResourceHintWebpackPlugin(),
new ScriptExtHtmlWebpackPlugin({
defaultAttribute: "async"
}),
new SubresourceIntegrityWebpackPlugin({
hashFuncNames: ["sha256", "sha384"],
// this is here as an example, comes at a perf cost so
// we probably only want to use it for 3rd party scripts
enabled: false // isProd(options)
}),
new ManifestPlugin(),
new BundleAnalyzerPlugin({
analyzerMode: isProd(options) ? "static" : "disabled",
openAnalyzer: false
})
],
module: {
rules: [
{
test: /\.js$/,
loader: "source-map-loader",
exclude: /node_modules|bower_components/
},
{
oneOf: [
{
test: /\.(css)$/,
use: [MiniCssExtractPlugin.loader, "css-loader"]
},
{
test: /\.(png|svg|jpg|jpeg|gif)$/,
use: ["file-loader"]
},
{
test: /\.purs$/,
exclude: /node_modules/,
use: {
loader: "purs-loader",
options: {
bundleOutput: "output/bundle.js",
// purs bundling breaks webpack's chunk splitting
bundle: false, // isProd(options),
warnings: true,
watch: options.watch,
pscArgs: {
// Set this to true and rebuild with
// `rm -rf output && npx pulp build -- --sourcemaps`
// to debug with sourcemaps.
// Disabled by default because it slow down
// and frequently breaks webpack/purs-loader,
// and the "locals" in the browser debugger don't
// make sense anyway.
sourceMaps: false
}
}
}
}
]
}
]
}
});