-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathwebpack.config.js
123 lines (120 loc) · 3.12 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
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(),
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/
},
{
oneOf: [
{
test: /\.(css)$/,
use: [ MiniCssExtractPlugin.loader, "css-loader" ]
},
{
test: /\.purs$/,
exclude: /node_modules/,
use: {
loader: "purs-loader",
options: {
src: [
'src/**/*.purs'
],
spago: true,
watch: !isProd(options),
pscIde: true
}
}
}
]
}
]
}
});