-
Notifications
You must be signed in to change notification settings - Fork 5
/
webpack.config.js
142 lines (137 loc) · 3.81 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
139
140
141
142
const path = require('path')
const webpack = require('webpack')
const htmlWebpackPlugin = require('html-webpack-plugin')
const extractTextPlugin = require('extract-text-webpack-plugin')
const _src = 'src'
const _test = 'tests'
const _dist = 'dist'
const _stylesheets = 'stylesheets'
const _static = 'static'
const isTesting = () => process.env.NODE_ENV === 'testing'
const isProduction = () => process.env.NODE_ENV === 'production'
module.exports = {
entry: {
app: `./${_src}/main.js`,
vendor: ['vue', 'axios', 'vue-router', 'vuex', 'vuex-router-sync', 'vuex-persistedstate', 'js-cookie', 'font-awesome/scss/font-awesome', 'buefy'],
},
output: {
path: path.resolve(__dirname, `./${_dist}`),
filename: isProduction() ? 'js/[name].[hash].js' : 'js/[name].js',
chunkFilename: isProduction() ? 'js/[name].[hash].js' : 'js/[name].js',
},
resolve: {
modules: [
path.resolve(__dirname, _src),
path.join(__dirname, 'node_modules'),
],
alias: {
'vue$': 'vue/dist/vue.esm.js',
'src': path.resolve(__dirname, './src'),
'tests': path.resolve(__dirname, './tests'),
},
extensions: ['.js', '.sass', '.scss', '.vue'],
},
module: {
rules: [
{
test: /\.vue$/,
use: ['vue-loader'],
},
{
test: /\.js$/,
use: ['babel-loader'],
include: [
path.resolve(__dirname, _src),
path.resolve(__dirname, _test),
],
exclude: /node_modules/,
},
{
test: /\.json$/,
use: ['json-loader'],
},
{
test: /\.pug$/,
use: ['pug-loader'],
},
{
test: /\.(sass|scss)$/,
use: extractTextPlugin.extract('css-loader?minimize!sass-loader?minimize'),
},
{
test: /\.css$/,
use: extractTextPlugin.extract('css-loader?minimize'),
},
{
test: /\.(png|jpg|jpeg|gif)$/,
loader: 'file-loader',
options: {
name: isProduction() ? `${_static}/images/[name].[hash].[ext]` : `${_static}/images/[name].[ext]`,
},
},
{
test: /\.(svg|eot|ttf)(\?v=\d+\.\d+\.\d+)?$/,
loader: 'file-loader',
options: {
name: isProduction() ? `${_static}/fonts/[name].[hash].[ext]` : `${_static}/fonts/[name].[ext]`,
// for font-awesome
publicPath: (path) => `../${path}`,
},
},
{
test: /\.woff(\d+)?(\?v=\d+\.\d+\.\d+)?$/,
loader: 'file-loader',
options: {
name: isProduction() ? `${_static}/fonts/[name].[hash].[ext]` : `${_static}/fonts/[name].[ext]`,
// for font-awesome
publicPath: (path) => `../${path}`,
},
},
],
},
plugins: [
new extractTextPlugin({
filename: isProduction() ? `${_stylesheets}/[name].[contenthash].css` : `${_stylesheets}/[name].css`,
}),
new webpack.ProvidePlugin({
Vue: ['vue', 'default'],
}),
new htmlWebpackPlugin({
filename: 'index.html',
template: 'index.html',
favicon: `${_src}/${_static}/favicon.ico`,
inject: true,
}),
],
devServer: {
contentBase: path.join(__dirname, _dist),
historyApiFallback: true,
noInfo: true,
},
devtool: '#eval-source-map',
}
if (!isTesting()) {
module.exports.plugins.push(
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
})
)
}
if (isProduction()) {
module.exports.devtool = '#source-map'
// https://vue-loader.vuejs.org/en/workflow/production.html
module.exports.plugins = (module.exports.plugins || []).concat([
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"',
},
}),
new webpack.optimize.UglifyJsPlugin({
comment: false,
compress: {
warnings: false,
},
}),
new webpack.optimize.OccurrenceOrderPlugin(),
])
}