-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
135 lines (124 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
const path = require('path');
const webpack = require('webpack');
const autoprefixer = require('autoprefixer');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const BundleTracker = require('webpack-bundle-tracker');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const SentryCliPlugin = require('@sentry/webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const { VueLoaderPlugin } = require('vue-loader');
var LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
const devMode = process.env.NODE_ENV !== 'production';
const hotReload = process.env.HOT_RELOAD === '1';
const vueRule = {
test: /\.vue$/,
use: 'vue-loader',
include: path.resolve('./static/src/js'),
exclude: /node_modules/
};
const styleRule = {
test: /\.(sa|sc|c)ss$/,
use: [
MiniCssExtractPlugin.loader,
{ loader: 'css-loader', options: { sourceMap: true } },
{ loader: 'postcss-loader', options: { plugins: () => [autoprefixer({ browsers: ['last 2 versions'] })] } },
'sass-loader'
]
};
const jsRule = {
test: /\.js$/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
plugins: ['@babel/plugin-proposal-object-rest-spread']
}
},
include: path.resolve('./static/src/js'),
exclude: /node_modules/
};
const assetRule = {
test: /.(jpg|png|woff(2)?|eot|ttf|svg)$/,
loader: 'file-loader'
};
const plugins = [
new BundleTracker({ filename: 'webpack-stats.json', path: path.resolve(__dirname, './static/dist/') }),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
}),
new VueLoaderPlugin(),
new MiniCssExtractPlugin({
filename: devMode ? '[name].css' : '[name].[hash].css',
chunkFilename: devMode ? '[id].css' : '[id].[hash].css'
}),
new BundleAnalyzerPlugin({ analyzerMode: 'static', openAnalyzer: false }),
new webpack.HotModuleReplacementPlugin(),
new CleanWebpackPlugin(),
new CopyWebpackPlugin([
{ from: './static/src/images/**/*', to: path.resolve('./static/dist/images/[name].[ext]'), toType: 'template' }
]),
new LodashModuleReplacementPlugin({
'collections': true,
'paths': true
})
];
if (devMode) {
styleRule.use = ['css-hot-loader', ...styleRule.use];
} else {
plugins.push(
new webpack.EnvironmentPlugin(['NODE_ENV', 'RAVEN_JS_DSN', 'SENTRY_ENVIRONMENT', 'SOURCE_VERSION'])
);
if (process.env.SENTRY_DSN) {
plugins.push(
new SentryCliPlugin({
include: '.',
release: process.env.SOURCE_VERSION,
ignore: ['node_modules', 'webpack.config.js'],
})
);
}
}
module.exports = {
entry: {
main: path.join(__dirname, './static/src/js/index.js'),
filter: path.join(__dirname, './static/src/js/filter.js')
},
output: {
path: path.resolve(__dirname, './static/dist/'),
filename: '[name]-[hash].js',
// publicPath: hotReload ? 'http://localhost:8080/' : ''
},
devtool: devMode ? 'cheap-eval-source-map' : 'source-map',
devServer: {
hot: true,
quiet: false,
headers: { 'Access-Control-Allow-Origin': '*' },
writeToDisk: true
},
module: { rules: [vueRule, jsRule, styleRule, assetRule] },
// externals: { jquery: 'jQuery', Sentry: 'Sentry' },
plugins,
optimization: {
// minimizer: [
// new UglifyJsPlugin({
// cache: true,
// parallel: true,
// sourceMap: true // set to true if you want JS source maps
// }),
// new OptimizeCSSAssetsPlugin({})
// ],
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendor',
chunks: 'initial',
},
}
}
},
};