-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.plugins.config.js
59 lines (49 loc) · 1.54 KB
/
webpack.plugins.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
require("dotenv").config();
const webpack = require("webpack");
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const ESLintPlugin = require("eslint-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const DIST_DIR = path.join(__dirname, "dist");
const HTML_DIR = path.join(DIST_DIR, "html");
const htmlPageNames = ["about", "canvas", "draw", "hide-n-seek", "math", "kannada", "capital", "theme"];
const multipleHtmlPlugins = htmlPageNames.map(
(name) =>
new HtmlWebpackPlugin({
template: `./src/html/${name}.html`, // relative path to the HTML files
filename: `${HTML_DIR}/${name}.html`, // output HTML files
chunks: [`${name}`] // respective JS files
})
);
const esLintOptions = {
extensions: [`js`],
exclude: [`/node_modules/`],
emitWarning: true,
failOnError: false
};
const plugins = [
new HtmlWebpackPlugin({
template: "src/html/index.html",
filename: `${HTML_DIR}/index.html`,
chunks: ["index"],
excludeChunks: ["server"],
title: "HMR for index.html"
}),
new webpack.HotModuleReplacementPlugin(),
new ESLintPlugin(esLintOptions),
new webpack.NoEmitOnErrorsPlugin(),
new MiniCssExtractPlugin({
filename: "styles/[name].css"
})
//new CopyPlugin({
// patterns: [
// {
// from: "./public/images",
// to: "./assets/images"
// }
// ]
//})
].concat(multipleHtmlPlugins);
console.log("mode", process.env.MODE);
module.exports = plugins;