-
Notifications
You must be signed in to change notification settings - Fork 103
/
webpack.config.js
138 lines (133 loc) · 3.35 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
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
const path = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const pkg = require('./package.json')
// Adds a banner to the top of each generated chunk.
const banner = `
${pkg.description}
v${pkg.version} ©${new Date().getFullYear()} ${pkg.author}
${pkg.homepage}
`.trim()
const siteConfig = require('./src/config')
// helper
const isProd = process.env.NODE_ENV === 'production'
const resolve = (...dir) => path.resolve(__dirname, ...dir)
const config = {
entry: './src/main.js',
output: {
path: resolve('dist'),
publicPath: siteConfig.base,
filename: isProd ? 'build.[chunkhash:5].js' : 'build.js'
},
resolve: {
alias: {
'@': resolve('src')
}
},
module: {
rules: [
// preLoaders
{
test: /\.(js|vue)$/,
enforce: 'pre',
use: [{
loader: 'eslint-loader',
options: {
formatter: require('eslint-friendly-formatter')
}
}],
include: [resolve('src'), resolve('test')]
},
// Loaders
{
test: /\.vue$/,
use: {
loader: 'vue-loader',
options: {
loaders: {
stylus: ExtractTextPlugin.extract({
use: 'css-loader?{"minimize":{"discardComments":{"removeAll":true}}}!stylus-loader',
fallback: 'vue-style-loader'
})
},
esModule: false
}
}
},
{
test: /\.js$/,
use: ['babel-loader'],
include: [resolve('src'), resolve('test')]
},
{
test: /\.(png|jpg|gif|svg)$/,
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]?[chunkhash:5]'
}
}]
}
],
noParse: [
/\.min\.js$/,
/es6-promise\.js$/
]
},
plugins: [
new HtmlWebpackPlugin({
// Configuration
template: resolve('src', 'tpl.html'),
filename: 'index.html',
minify: false,
chunksSortMode: 'dependency',
// Other custom metadata
title: siteConfig.blogTitle || '',
blogDescription: siteConfig.blogDescription || '',
blogAuthor: siteConfig.blogAuthor || '',
blogKeywords: siteConfig.blogKeywords || '',
favicon: siteConfig.favicon || false,
base: siteConfig.base || '/'
}),
new ExtractTextPlugin({
filename: isProd ? 'build.[chunkhash:5].css' : 'build.css',
disable: false,
allChunks: true
})
],
devServer: {
compress: true,
contentBase: resolve('static'),
historyApiFallback: true,
host: '0.0.0.0',
noInfo: true
},
devtool: isProd ? '#cheap-module-source-map' : '#eval-source-map'
}
// production build setting
if (isProd) {
config.plugins = (config.plugins || []).concat([
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
},
output: {
comments: false
}
}),
new webpack.BannerPlugin(banner),
new CopyWebpackPlugin([
{
from: resolve('static'),
to: resolve('dist'),
ignore: ['.*']
}
])
])
}
module.exports = config