-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.base.conf.js
77 lines (74 loc) · 1.79 KB
/
webpack.base.conf.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
const path = require("path");
const merge = require("webpack-merge");
const htmlWebpackPlugin = require("html-webpack-plugin");
const { getEntry } = require("./utils");
const cleanWebpackPlugin = require("clean-webpack-plugin").CleanWebpackPlugin;
const entry = Object.create(null);
let htmlEntry = Object.create(null);
const htmlWebpackPlugins = [];
getEntry(
path.join(__dirname, "../src/js"),
{
extname: ".js",
},
entry
);
getEntry(
path.join(__dirname, "../src/page"),
{
extname: ".html",
deep: true,
},
htmlEntry
);
const favicon = path.join(__dirname, "../src/image/logo/shier.png");
for (let page in htmlEntry) {
let chunkName = path.basename(page, path.extname(page));
let chunks = Object.prototype.hasOwnProperty.call(entry, chunkName)
? [chunkName]
: [];
let option = {
template: htmlEntry[page],
filename: path.join(__dirname, "../app/view", page + ".html"),
chunks,
minify: process.env.NODE_ENV !== "development",
};
if (!/^common\//.test(page)) {
option.favicon = favicon;
}
htmlWebpackPlugins.push(new htmlWebpackPlugin(option));
}
const baseConf = merge({
entry,
output: {
path: path.join(__dirname, "../public/static/js"),
publicPath: "/assets/static/js/",
},
module: {
rules: [
{
test: /\.js$/,
include: path.join(__dirname, "../src/js/**/*"),
loader: "babel-loader",
},
{
test: /\.html$/,
include: path.join(__dirname, "../src/page/**/*"),
loader: "html-loader",
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
exclude: /node_modules/,
include: [path.join(__dirname, "../src/image")],
loader: "url-loader",
options: {
limit: 10000,
name: "[name].[ext]",
outputPath: "../image",
},
},
],
},
plugins: [new cleanWebpackPlugin(), ...htmlWebpackPlugins],
});
module.exports = baseConf;