-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.babel.js
132 lines (113 loc) · 2.88 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
const path = require('path')
const DefinePlugin = require('webpack/lib/DefinePlugin')
const HotModuleReplacementPlugin = require('webpack/lib/HotModuleReplacementPlugin')
const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin')
const ProgressPlugin = require('webpack/lib/ProgressPlugin')
const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin')
// VARS
const NODE_ENV = process.env.NODE_ENV || 'development'
const ENV_DEVELOPMENT = NODE_ENV === 'development'
const ENV_PRODUCTION = NODE_ENV === 'production'
const ENV_TEST = NODE_ENV === 'test'
const HOST = process.env.WEBPACK_HOST || '0.0.0.0'
const PORT = process.env.WEBPACK_PORT || 3000
// LOADERS
const rules = {
js: { test: /\.js$/, exclude: /node_modules|dist/, loader: 'babel-loader' },
vue: { test: /\.vue$/, exclude: /node_modules|dist/, loader: 'vue-loader' }
}
// CONFIG
const config = module.exports = {}
config.resolve = {
extensions: ['.js', '.vue'],
modules: [
path.resolve('.'),
'node_modules'
],
alias: {
vue: 'vue/dist/vue.js'
}
}
config.plugins = [
new LoaderOptionsPlugin({
debug: false,
minimize: true
}),
new DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(NODE_ENV)
})
]
// DEVELOPMENT or PRODUCTION
if (ENV_DEVELOPMENT || ENV_PRODUCTION) {
config.entry = {
'vuex-form': ['./src/index.js']
}
config.output = {
filename: '[name].js',
path: path.resolve('./dist'),
publicPath: '/',
// export itself to a global var
libraryTarget: 'var',
// name of the global var: "Foo"
library: 'VuexForm'
}
}
// DEVELOPMENT
if (ENV_DEVELOPMENT) {
config.devtool = 'source-map'
config.module = {
rules: [ rules.js, rules.vue ]
}
config.plugins.push(
new HotModuleReplacementPlugin(),
new ProgressPlugin()
)
config.devServer = {
contentBase: './src',
historyApiFallback: true,
host: HOST,
hot: true,
port: PORT,
stats: {
cached: true,
cachedAssets: true,
chunks: true,
chunkModules: false,
colors: true,
hash: false,
reasons: true,
timings: true,
version: false
}
}
}
// PRODUCTION
if (ENV_PRODUCTION) {
config.devtool = 'hidden-source-map'
config.output.filename = '[name].min.js'
config.module = {
rules: [ rules.js, rules.vue ]
}
config.plugins.push(
new UglifyJsPlugin({
comments: false,
compress: {
dead_code: true, // eslint-disable-line camelcase
screw_ie8: true, // eslint-disable-line camelcase
unused: true,
warnings: false
},
mangle: {
screw_ie8: true // eslint-disable-line camelcase
}
})
)
}
// TEST
if (ENV_TEST) {
config.devtool = 'inline-source-map'
config.module = {
rules: [ rules.js, rules.vue ]
}
config.externals = { 'jsdom': 'window' }
}