-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.js
144 lines (132 loc) · 3.83 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
143
require('dotenv').config();
const path = require('path');
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin');
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const ENV = process.env.NODE_ENV;
const isProd = ENV == 'production';
const pkgJson = require('./package.json');
const PUBLIC_PATH = process.env.PUBLIC_PATH + '/build/';
const webpackConfig = {
mode: isProd ? 'production' : 'development',
entry: {
app : '~/app',
//lib : [],
vendor : ['vue', 'vuex', 'vue-router', 'vue-head'],
//common : [],
},
output: {
path: path.resolve(__dirname, 'public/build'),
chunkFilename: '[name]-[chunkhash].chunk.js',
filename: '[name]-bundle.js',
},
module: {
rules: [
{
test: /\.vue$/,
exclude: [/node_modules(?!\/\@zoomcarindia)/],
loader: 'vue-loader',
}, {
test: /\.js$/,
exclude: [/node_modules(?!\/\@zoomcarindia)/],
use: 'babel-loader'
}, {
test: /\.(sa|sc|c)ss$/,
exclude: [/node_modules(?!\/\@zoomcarindia)/],
use: [
isProd ? MiniCssExtractPlugin.loader : 'style-loader',
'css-loader?sourceMap',
'postcss-loader?sourceMap',
'sass-loader?sourceMap'
],
}, {
test: /\.(png|jpg|jpeg|gif|woff|woff2|eot|ttf|svg)$/,
exclude: [/node_modules(?!\/\@zoomcarindia)/],
use: 'file-loader'
},
],
},
resolve: {
alias:{
'~': path.resolve(__dirname, 'src'),
'vue$': `vue/dist/vue.runtime${isProd?'.min':''}.js`,
'vue-router$': `vue-router/dist/vue-router${isProd?'.min':''}.js`,
'vuex$': `vuex/dist/vuex${isProd?'.min':''}.js`,
},
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.DefinePlugin({
'process.env': `"${ENV}"`
}),
new HtmlWebpackPlugin({
template : './src/index.ejs',
filename : isProd ? '../index.html': 'index.html',
env : process.env,
pkg : pkgJson,
chunksSortMode(a, b) {
const order = ['app', 'common', 'vendor', 'lib'];
return order.indexOf(b.names[0]) - order.indexOf(a.names[0]);
}
}),
new FriendlyErrorsWebpackPlugin(),
new VueLoaderPlugin(),
new MiniCssExtractPlugin({
filename: isProd ? '[name].[contenthash].css' : '[name].css',
chunkFilename: isProd ? '[id].[contenthash].css' : '[id].css',
}),
],
devtool: !isProd ? 'source-map' : false
};
/**
// WP Config for development environment
**/
if(!isProd) {
webpackConfig.output.sourceMapFilename = '[file].map';
//webpackConfig.output.publicPath = process.env.PUBLIC_PATH || '/';
webpackConfig.output.publicPath = '/';
webpackConfig.devServer = {
host: '0.0.0.0',
port: 9393,
//https: true,
inline: true,
hot: true,
contentBase: 'public',
historyApiFallback: {
index: 'index.html',
},
stats: {
chunks: false
}
}
}
/**
// WP Config for production environment
**/
if(isProd) {
webpackConfig.output.publicPath = PUBLIC_PATH;
}
webpackConfig.plugins.push(
new SWPrecacheWebpackPlugin({
cacheId: pkgJson.name,
filepath: path.join(__dirname, '/public/sw.js'),
maximumFileSizeToCacheInBytes: 4194304,
minify: isProd,
/*runtimeCaching: [{
urlPattern: new RegExp('https://api.zoomcar.com/'),
handler: 'networkFirst'
}],*/
staticFileGlobs: [
'./public/index.html',
'./public/{img,css,js,fav}/*.*',
'./public/build/*.*'
],
stripPrefix: './public',
navigateFallback: '/index.html'
})
);
module.exports = webpackConfig;