This repository has been archived by the owner on May 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
webpack.extra-config.js
79 lines (77 loc) · 2.35 KB
/
webpack.extra-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
const HtmlWebpackPlugin = require("html-webpack-plugin");
const merge = require("webpack-merge");
const { compact } = require("lodash");
module.exports = config => {
config.devtool =
process.env.NODE_ENV === "development"
? "eval-cheap-module-source-map"
: "";
let cssRules;
if (process.env.NODE_ENV === "development") {
config.module.rules = config.module.rules.map(rule => {
if (rule.use && rule.use[0] === "css-hot-loader") {
// do nothing
} else {
return rule;
}
});
cssRules = [
{
test: /\.?css$/,
use: [
"vue-style-loader",
{ loader: "css-loader", options: { importLoaders: 1 } },
"postcss-loader"
]
}
];
} else {
config.module.rules = config.module.rules.map(rule => {
try {
if (rule.use && rule.use[0].match("mini-css-extract-plugin")) {
// do nothing
} else {
return rule;
}
} catch (error) {
return rule;
}
});
cssRules = [
{
test: /\.?css$/,
use: [
"css-hot-loader",
"vue-style-loader",
{ loader: "css-loader", options: { importLoaders: 1 } },
"postcss-loader"
]
}
];
}
config.module.rules = compact(config.module.rules);
config.module.rules.push(...cssRules);
config.module.rules.push({
test: /\.worker\.js$/,
use: { loader: "worker-loader", options: { inline: true } }
});
config = merge(config, {
resolve: {
alias: {
src: `${__dirname}/src`,
assets: `${__dirname}/src/assets`,
components: `${__dirname}/src/components`,
node_modules: `${__dirname}/node_modules`
}
},
plugins: [
new HtmlWebpackPlugin({
title: "Describo",
template: "src/renderer/index.html",
hash: true
})
]
});
// console.log(JSON.stringify(config, null, 2));
return config;
};