forked from zgatrying/resume
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack-dist.config.js
113 lines (108 loc) · 3.16 KB
/
webpack-dist.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
const fs = require('fs');
const path = require('path');
const { spawnSync } = require('child_process');
const findChrome = require('chrome-finder');
const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin');
const DefinePlugin = require('webpack/lib/DefinePlugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const EndWebpackPlugin = require('end-webpack-plugin');
const { WebPlugin } = require('web-webpack-plugin');
const ghpages = require('gh-pages');
function publishGhPages() {
return new Promise((resolve, reject) => {
ghpages.publish(outputPath, { dotfiles: true }, (err) => {
if (err) {
reject(err);
} else {
resolve();
}
})
});
}
const outputPath = path.resolve(__dirname, '.public');
module.exports = {
output: {
path: outputPath,
publicPath: '',
filename: '[name]_[chunkhash:8].js',
},
resolve: {
// 加快搜索速度
modules: [path.resolve(__dirname, 'node_modules')],
// es tree-shaking
mainFields: ['jsnext:main', 'browser', 'main'],
},
module: {
rules: [
{
test: /\.scss$/,
// 提取出css
loaders: ExtractTextPlugin.extract({
fallback: 'style-loader',
// 压缩css
use: ['css-loader?minimize', 'postcss-loader', 'sass-loader']
}),
include: path.resolve(__dirname, 'src')
},
{
test: /\.css$/,
// 提取出css
loaders: ExtractTextPlugin.extract({
fallback: 'style-loader',
// 压缩css
use: ['css-loader?minimize', 'postcss-loader'],
}),
},
{
test: /\.(gif|png|jpe?g|eot|woff|ttf|svg|pdf)$/,
loader: 'base64-inline-loader',
},
]
},
entry: {
main: './src/main.js',
},
plugins: [
new DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production')
}
}),
new UglifyJsPlugin({
// 最紧凑的输出
beautify: false,
// 删除所有的注释
comments: false,
compress: {
// 在UglifyJs删除没有用到的代码时不输出警告
warnings: false,
// 删除所有的 `console` 语句,可以兼容ie浏览器
drop_console: true,
// 内嵌定义了但是只用到一次的变量
collapse_vars: true,
// 提取出出现多次但是没有定义成变量去引用的静态值
reduce_vars: true,
}
}),
new WebPlugin({
template: './src/index.html',
filename: 'index.html',
}),
new ExtractTextPlugin({
filename: '[name]_[contenthash:8].css',
allChunks: true,
}),
new EndWebpackPlugin(async () => {
// 自定义域名
fs.writeFileSync(path.resolve(outputPath, 'CNAME'), 'resume.wuhaolin.cn');
await publishGhPages();
// 调用 Chrome 渲染出 PDF 文件
const chromePath = findChrome();
spawnSync(chromePath, ['--headless', '--disable-gpu', `--print-to-pdf=${path.resolve(outputPath, 'resume.pdf')}`,
'http://resume.wuhaolin.cn' // 这里注意改成你的在线简历的网站
]);
// 重新发布到 ghpages
await publishGhPages();
}),
]
};