/
webpack.config.js
94 lines (83 loc) · 2.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
require('dotenv').config()
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const path = require('path')
const nodeEnv = process.env.NODE_ENV || 'development'
let outputPath
let plugins = [
// added vendor chunk
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
filename: process.env.NODE_ENV === 'production' ? 'build/vendor.[hash].js' : 'vendor.js',
minChunks: Infinity
})
]
// set client environment variabels
plugins.push(new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
FIREBASE_APIKEY: JSON.stringify(process.env.FIREBASE_APIKEY),
FIREBASE_AUTHDOMAIN: JSON.stringify(process.env.FIREBASE_AUTHDOMAIN),
FIREBASE_DATABASEURL: JSON.stringify(process.env.FIREBASE_DATABASEURL),
FIREBASE_PROJECTID: JSON.stringify(process.env.FIREBASE_PROJECTID),
FIREBASE_STORAGEBUCKET: JSON.stringify(process.env.FIREBASE_STORAGEBUCKET),
FIREBASE_MESSAGINGSENDERID: JSON.stringify(process.env.FIREBASE_MESSAGINGSENDERID)
}
}))
// production config
if (nodeEnv === 'production') {
// webpack copy
const CopyWebpackPlugin = require('copy-webpack-plugin')
// minify appjs
const UglifyJsPlugin = webpack.optimize.UglifyJsPlugin
plugins.push(new UglifyJsPlugin({ minimize: true }))
// copy assets to dist
plugins.push(new CopyWebpackPlugin([
{ from: 'public' }
]))
// generate index html
plugins.push(new HtmlWebpackPlugin({
inject: true,
template: './internals/index.html',
filename: 'index.html'
}))
// set js bundle name
outputPath = path.resolve(__dirname, 'dist')
} else {
// set js bundle name
outputPath = path.resolve(__dirname, 'public/build')
}
// default config
module.exports = {
entry: {
app: './src/client/index.js',
vendor: ['vue', 'vuex', 'vue-router', 'firebase', 'string-manager']
},
output: {
filename: process.env.NODE_ENV === 'production' ? 'build/[name].[hash].js' : '[name].js',
path: outputPath,
publicPath: '/'
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /(node_modules)/,
loader: 'babel-loader',
query: {
presets: ['es2015']
}
},
{
test: /\.vue$/,
loader: 'vue-loader'
}
]
},
resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js'
}
},
plugins
}