/
webpack.config.js
151 lines (141 loc) · 3.76 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
const currentTask = process.env.npm_lifecycle_event;
const path = require("path");
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const HtmlWebpackPartialsPlugin = require("html-webpack-partials-plugin");
const HtmlWebpackHarddiskPlugin = require("html-webpack-harddisk-plugin");
const ExtraWatchWebpackPlugin = require("extra-watch-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const fse = require("fs-extra");
const postCSSPlugins = [
require("postcss-import"),
require("postcss-mixins"),
require("postcss-simple-vars"),
require("postcss-nested"),
require("autoprefixer"),
];
class RunAfterCompile {
apply(compiler) {
compiler.hooks.done.tap("Copy CNAME", function () {
fse.copySync("./CNAME", "../docs/CNAME");
});
}
}
const partialsList = [
{ path: path.join(__dirname, "./partials/_links.html"), location: "head" },
{ path: path.join(__dirname, "partials/_navbar.html") },
{ path: path.join(__dirname, "partials/_about.html") },
{ path: path.join(__dirname, "partials/_installation.html") },
{ path: path.join(__dirname, "partials/_usage.html") },
{ path: path.join(__dirname, "partials/_configuration.html") },
{ path: path.join(__dirname, "partials/_contribute.html") },
{ path: path.join(__dirname, "partials/_license.html") },
{ path: path.join(__dirname, "partials/_footer.html") },
];
let cssConfig = {
test: /\.css$/i,
use: [
"css-loader?url=false",
{
loader: "postcss-loader",
options: {
postcssOptions: {
plugins: postCSSPlugins,
},
},
},
],
};
const pluginList = [
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
}),
new ExtraWatchWebpackPlugin({
files: ["./partials/*.html"],
}),
new HtmlWebpackPlugin({
title:
"update_repo | Automate the update of multiple local Git repository clones",
alwaysWriteToDisk: true,
}),
new HtmlWebpackPartialsPlugin(partialsList),
new HtmlWebpackHarddiskPlugin(),
new CleanWebpackPlugin(),
];
let config = {
entry: "./assets/scripts/Main.js",
output: {
filename: "bundled.js",
path: path.resolve(__dirname, "../docs"),
},
plugins: pluginList,
module: {
rules: [cssConfig],
},
};
if (currentTask == "dev") {
cssConfig.use.unshift("style-loader");
config.devServer = {
static: [path.resolve(__dirname, "../docs")],
hot: true,
port: 3000,
dev: { writeToDisk: true },
};
config.mode = "development";
}
if (currentTask == "build") {
config.module.rules.push({
test: /\.js$/,
exclude: /(node_modules)/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-env"],
},
},
});
cssConfig.use.unshift(MiniCssExtractPlugin.loader);
postCSSPlugins.push(
require("cssnano")({
preset: [
"default",
{
discardComments: {
removeAll: true,
},
},
],
})
);
pluginList.push(
new MiniCssExtractPlugin({ filename: "styles.[chunkhash].css" }),
new RunAfterCompile()
);
config.output = {
filename: "[name].[chunkhash].js",
chunkFilename: "[name].[chunkhash].js",
path: path.resolve(__dirname, "../docs"),
};
config.mode = "production";
config.optimization = {
splitChunks: { chunks: "all" },
// minimizer: [
// new OptimizeCSSAssetsPlugin({
// // cssnano configuration
// cssProcessorPluginOptions: {
// preset: [
// "default",
// {
// discardComments: {
// removeAll: true,
// },
// },
// ],
// },
// }),
// ],
};
}
module.exports = config;