-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
executable file
·71 lines (63 loc) · 2.33 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
const webpack = require('webpack')
const merge = require('webpack-merge')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const NODE_ENV = process.env.NODE_ENV || 'development'
const isDebug = NODE_ENV !== 'production'
const PUBLIC_PATH = process.env.PUBLIC_PATH || '/'
const TITLE = process.env.npm_package_keywords_0
const DESCRIPTION = process.env.npm_package_description
const KEYWORDS = []
let i = 0
let keyword = ''
while ((keyword = process.env['npm_package_keywords_' + String(i++)])) {
KEYWORDS.push(keyword)
}
const VERSION = process.env.npm_package_version
const SOURCE_PAGE = process.env.npm_package_repository_url.match(/(https?:\/\/.+)\.git$/)[1]
const HOME_PAGE = process.env.npm_package_homepage
const AUTHOR = process.env.npm_package_author_name
const CONTACT = process.env.npm_package_author_url
const LICENSE = SOURCE_PAGE + '/blob/master/LICENSE'
const CREATE_AT = '2016-10-21T01:30:00+0800'
const UPDATE_AT = process.env.PUBLISH_DATE || new Date().toISOString()
const config = merge(
require('./webpack/base'),
isDebug ? require('./webpack/dev') : require('./webpack/prod'), {
plugins: [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify(NODE_ENV),
'TITLE': JSON.stringify(TITLE),
'DESCRIPTION': JSON.stringify(DESCRIPTION),
'VERSION': JSON.stringify(VERSION),
'SOURCE_PAGE': JSON.stringify(SOURCE_PAGE),
},
}),
new HtmlWebpackPlugin({
template: './src/index.html',
filename: 'index.html',
html5: true,
minify: isDebug ? false : {
collapseWhitespace: true
},
cache: isDebug,
PUBLIC_PATH,
TITLE,
DESCRIPTION,
KEYWORDS: KEYWORDS.join(', '),
AUTHOR,
CONTACT,
LICENSE,
SOURCE_PAGE,
HOME_PAGE,
CREATE_AT,
UPDATE_AT
})
]
}
)
if (process.env.ANALYZE) {
const {BundleAnalyzerPlugin} = require('webpack-bundle-analyzer')
config.plugins.unshift(new BundleAnalyzerPlugin({analyzerMode: 'static'}))
}
module.exports = config