-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathwebpack.config.js
81 lines (71 loc) · 1.91 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
/* global process */
const path = require("path");
const webpack = require("webpack");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const childProcess = require("child_process");
const packageVersion = require("./package.json").version;
const buildVersion = childProcess
.execSync("git rev-list HEAD --count")
.toString();
function makeConfig(mode) {
let config = {
entry: ["./src/js/app.js", "./src/scss/app.scss"],
target: "web",
output: {
path: path.resolve("dist"),
filename: "js/main.js"
},
module: {
rules: [
{
test: /\.(woff(2)?|eot|ttf|otf|svg|png)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
type: "asset",
parser: {
dataUrlCondition: {
maxSize: 8 * 1024 // in bytes
}
},
generator: {
// the file path to use when emitting a file
filename: "assets/[hash][ext][query]"
}
},
{
test: /\.scss$/,
use: [
"style-loader",
{
loader: MiniCssExtractPlugin.loader,
options: {
esModule: false,
publicPath: "../" // prepend this to url() in the CSS
}
},
"css-loader",
"sass-loader"
]
}
]
},
plugins: [
new CopyPlugin({
patterns: [{ from: "src/index.html", to: "index.html" }]
}),
new MiniCssExtractPlugin({
filename: "css/[name].css"
}),
new webpack.DefinePlugin({
BUILD_VERSION: JSON.stringify(packageVersion + "." + buildVersion)
})
]
};
if (mode === "development") {
config.devtool = "source-map";
config.output.sourceMapFilename = "[file].map";
}
return config;
}
module.exports = (_env, argv) => {
return makeConfig(argv.mode);
};