-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
107 lines (104 loc) · 3.28 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
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const env = require('./server/.env');
const ManifestPlugin = require('webpack-manifest-plugin');
const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const googleClientId = `"${env.GOOGLE_CLIENT_ID}"`;
const facebookClientId = `"${env.FACEBOOK_CLIENT_ID}"`;
const apiHost = `"${env.SERVER_URL}"`;
module.exports = {
entry: './src/main.js',
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
output: {
path: path.resolve(__dirname, './dist'),
publicPath: '/',
filename: 'build.js'
},
module: {
rules: [
{ test: /\.vue$/, loader: 'vue-loader' },
{ test: /\.css$/, loader: 'style-loader!css-loader' },
{ test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/ },
{
test: /\.(png|jpg|gif|ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file-loader',
options: { name: '[name].[ext]?[hash]' }
},
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'url-loader?limit=10000&minetype=application/font-woff'
}
]
},
devServer: {
contentBase: path.join(__dirname, 'dist'),
historyApiFallback: true,
noInfo: true
},
performance: {
hints: false
},
optimization: {
splitChunks: {
chunks: 'all',
cacheGroups: {
vue: {
name: 'vue',
test: /\/node_modules\/vue.*/
},
vendors: { test: /\/node_modules\/[^vue].*/, name: 'vendors' }
}
}
},
devtool: '#eval-source-map',
plugins: [
new webpack.DefinePlugin({
__API__: apiHost,
__GOOGLE_CLIENT_ID__: `${googleClientId}`,
__FACEBOOK_CLIENT_ID__: `${facebookClientId}`
}),
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
new HtmlWebpackPlugin({
template: 'index.ejs',
hash: true
}),
new ManifestPlugin({
fileName: 'asset-manifest.json'
}),
new CopyWebpackPlugin([
{ from: 'src/assets/manifest.json' },
{ from: 'src/assets/logo.png' }
]),
new SWPrecacheWebpackPlugin({
// By default, a cache-busting query parameter is appended to requests
// used to populate the caches, to ensure the responses are fresh.
// If a URL is already hashed by Webpack, then there is no concern
// about it being stale, and the cache-busting can be skipped.
dontCacheBustUrlsMatching: /\.\w{8}\./,
filename: 'service-worker.js',
logger(message) {
if (message.indexOf('Total precache size is') === 0) {
// This message occurs for every build and is a bit too noisy.
return;
}
console.log(message);
},
minify: true, // minify and uglify the script
navigateFallback: '/',
staticFileGlobsIgnorePatterns: [/\.map$/, /asset-manifest\.json$/]
})
]
};
if (['production', 'staging'].indexOf(process.env.NODE_ENV) > -1) {
module.exports.devtool = '#source-map';
// http://vue-loader.vuejs.org/en/workflow/production.html
module.exports.plugins = (module.exports.plugins || []).concat([
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
})
]);
}