-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.babel.js
144 lines (134 loc) · 2.78 KB
/
webpack.config.babel.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
import path from 'path';
import webpack from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import cssnext from 'postcss-cssnext';
import websiteJson from './config/website.json';
import webpackEnv from './config/webpack';
import palette from './config/palette.json';
const webpackBaseConfig = {
entry: (() => {
const entryObj = {};
for (const key in websiteJson.pages) {
if ({}.hasOwnProperty.call(websiteJson.pages, key)) {
entryObj[key] = path.join(__dirname, 'src', 'js', websiteJson.pages[key].entry);
}
}
return entryObj;
})(),
output: {
path: path.join(__dirname, 'build'),
filename: '[hash:5].js',
publicPath: '/',
},
module: {
rules: [
{
test: /\.js$/,
include: /src\/js/,
use: 'babel-loader',
},
{
test: /\.(jpg|png|gif)$/,
include: [
/src\/images/,
],
loader: 'url-loader',
options: {
limit: 10000,
name: '[hash:7].[ext]',
},
},
{
test: /\.svg$/,
include: /src\/images/,
use: [
{
loader: 'file-loader',
},
{
loader: 'svgo-loader',
options: {
plugins: [
{ removeTitle: true },
{ collapseGroups: false },
],
},
},
],
},
{
test: /\.pug$/,
include: /src\/view/,
use: 'pug-loader',
},
{
test: /\.(ttf|eot|svg|woff(2)?)(\?[a-z0-9=&.]+)?$/,
loader: 'file-loader',
options: {
name: '[hash:7].[ext]',
},
},
],
cssRule: {
test: /\.css$/,
include: /src\/css/,
use: {
css: 'css-loader',
postcss: 'postcss-loader',
},
},
},
plugins: {
// webpack environment variables
webpackEnvironment: new webpack.DefinePlugin({
'process.env': webpackEnv,
}),
htmlWebpackPlugin: (() => {
const htmlArr = [];
/**
* return a html object
*/
const htmlWebpackObj = (page, language) => (
new HtmlWebpackPlugin({
template: `src/view/${page}.pug`,
inject: 'body',
filename: `${page}.html`,
favicon: 'src/images/favico.png',
minify: {
collapseBooleanAttributes: true,
collapseWhitespace: true,
minifyCSS: true,
minifyJS: true,
quoteCharacter: '\'',
removeComments: true,
removeEmptyAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
},
teams: websiteJson.teams,
})
);
/**
* generate .html file of each page
*/
Object.keys(websiteJson.pages).forEach((page) => {
htmlArr.push(htmlWebpackObj(page));
});
return htmlArr;
})(),
loaderOptionsPlugin: new webpack.LoaderOptionsPlugin({
options: {
postcss: [
cssnext({
features: {
customProperties: {
variables: palette,
},
},
}),
],
}
}),
},
};
export default webpackBaseConfig;