-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.common.js
More file actions
120 lines (117 loc) · 3.96 KB
/
Copy pathwebpack.common.js
File metadata and controls
120 lines (117 loc) · 3.96 KB
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
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyPlugin = require("copy-webpack-plugin");
const _ = require('lodash');
module.exports = {
entry: {
boilerplate: './src/boilerplate.js',
index: './src/index.js',
print: './src/print.js'
},
plugins: [
new CleanWebpackPlugin(),
new CopyPlugin({
patterns: [
'./src/favicon.ico'
]
}),
new HtmlWebpackPlugin({
template: './index.html',
excludeChunks: ['print']
}),
new HtmlWebpackPlugin({
filename: 'print.html',
template: './print.html',
excludeChunks: ['index']
}),
new HtmlWebpackPlugin({
filename: 'portfolio.html',
template: './portfolio.html',
excludeChunks: ['index']
}),
],
output: {
//filename: '[name].[contenthash].js',
//not using hash as the dist folder will be versioned
filename: '[name].js',
publicPath: '',
},
optimization: {
runtimeChunk: 'single',
usedExports: true,
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('@', '')}`;
}
}
}
},
},
module: {
rules: [
{
test: /\.s[ac]ss$/i,
use: [
// Creates `style` nodes from JS strings
"style-loader",
// Translates CSS into CommonJS
"css-loader",
{
// Run post css actions
loader: 'postcss-loader',
options: {
// post css plugins, can be exported to postcss.config.js
postcssOptions: {
plugins: [
[
"autoprefixer",
{
//options
}
]
]
}
}
},
// Compiles Sass to CSS
{
loader: "sass-loader",
options: {
implementation: require("dart-sass")
}
}
],
},
{
test: /\.html$/i,
loader: 'html-loader',
options: {
preprocessor: (content, loaderContext) => {
try {
const compiled = _.template(content);
return compiled(require('./src/data'));
} catch (error) {
loaderContext.emitError(error); //comment if you'd like to bypass the errors
return content;
}
}
}
},
{
test: /\.(png|svg|jpg|jpeg|gif|ico)$/i,
type: 'asset/resource',
}
],
},
};