Repository navigation
Expand file tree
/
Copy pathwebpack.config.js
More file actions
128 lines (126 loc) · 3.04 KB
/
Copy pathwebpack.config.js
File metadata and controls
128 lines (126 loc) · 3.04 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
C9F3
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
const Webpack = require("webpack");
const Path = require("path");
const TerserPlugin = require("terser-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const FileManagerPlugin = require("filemanager-webpack-plugin");
const opts = {
rootDir: process.cwd(),
devBuild: process.env.NODE_ENV !== "production"
};
module.exports = {
entry: {
app: "./src/js/app.js"
},
mode: process.env.NODE_ENV === "production" ? "production" : "development",
devtool:
process.env.NODE_ENV === "production" ? "source-map" : "inline-source-map",
output: {
path: Path.join(opts.rootDir, "dist"),
pathinfo: opts.devBuild,
filename: "js/[name].js",
chunkFilename: 'js/[name].js',
},
performance: { hints: false },
optimization: {
minimizer: [
new TerserPlugin({
parallel: true,
terserOptions: {
ecma: 5
}
}),
new CssMinimizerPlugin({})
],
runtimeChunk: false
},
plugins: [
// Extract css files to seperate bundle
new MiniCssExtractPlugin({
filename: "css/app.css",
chunkFilename: "css/app.css"
}),
// Copy fonts and images to dist
new CopyWebpackPlugin({
patterns: [
{ from: "src/fonts", to: "fonts" },
{ from: "src/img", to: "img" }
]
}),
// Copy dist folder to static
...(process.env.NODE_ENV === "production")? [
new FileManagerPlugin({
events: {
onEnd: {
copy: [
{ source: "./dist/", destination: "./static" }
]
}
},
})
] : [],
],
module: {
rules: [
// Babel-loader
{
test: /\.js$/,
exclude: /(node_modules)/,
use: {
loader: "babel-loader",
options: {
cacheDirectory: true
}
}
},
// Css-loader & sass-loader
{
test: /\.(sa|sc|c)ss$/,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
"postcss-loader",
{
loader: "sass-loader",
options: {
sassOptions: {
silenceDeprecations: ["import", "color-functions", "global-builtin", "if-function", "legacy-js-api"]
}
}
}
]
},
// Load fonts
{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
type: "asset/resource",
generator: {
filename: "fonts/[name][ext]"
}
},
// Load images
{
test: /\.(png|jpg|jpeg|gif)(\?v=\d+\.\d+\.\d+)?$/,
type: "asset/resource",
generator: {
filename: "img/[name][ext]"
}
},
]
},
resolve: {
extensions: [".js", ".scss"],
modules: ["node_modules"],
alias: {
request$: "xhr"
}
},
devServer: {
static: {
directory: Path.join(__dirname, "static")
},
port: 8080,
open: true
}
};