-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.common.js
85 lines (84 loc) · 3.32 KB
/
webpack.common.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
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin,
CleanPlugin = require('clean-webpack-plugin'),
LodashPlugin = require('lodash-webpack-plugin'),
path = require('path'),
webpack = require('webpack');
// Common configuration, with extensions in webpack.dev.js and webpack.prod.js.
module.exports = {
bail: true,
context: __dirname,
entry: {
main: './assets/js/app.js',
head_async: ['lazysizes'],
},
module: {
rules: [
{
test: /\.js$/,
include: /(assets\/js|assets\\js|stencil-utils)/,
use: {
loader: 'babel-loader',
options: {
plugins: [
'@babel/plugin-syntax-dynamic-import', // add support for dynamic imports (used in app.js)
'lodash', // Tree-shake lodash
],
presets: [
['@babel/preset-env', {
loose: true, // Enable "loose" transformations for any plugins in this preset that allow them
modules: false, // Don't transform modules; needed for tree-shaking
useBuiltIns: 'usage', // Tree-shake babel-polyfill
targets: '> 1%, last 2 versions, Firefox ESR',
corejs: '^3.4.1',
}],
],
},
},
},
{
test: require.resolve('jquery'),
use: [{
loader: 'expose-loader',
options: '$',
}],
},
],
},
output: {
chunkFilename: 'theme-bundle.chunk.[name].js',
filename: 'theme-bundle.[name].js',
path: path.resolve(__dirname, 'assets/dist'),
},
performance: {
hints: 'warning',
maxAssetSize: 1024 * 300,
maxEntrypointSize: 1024 * 300,
},
plugins: [
new CleanPlugin(['assets/dist'], {
verbose: false,
watch: false,
}),
new LodashPlugin, // Complements babel-plugin-lodash by shrinking its cherry-picked builds further.
new webpack.ProvidePlugin({ // Provide jquery automatically without explicit import
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
}),
new BundleAnalyzerPlugin({
analyzerMode: 'static',
openAnalyzer: false,
}),
],
resolve: {
alias: {
jquery: path.resolve(__dirname, 'node_modules/jquery/dist/jquery.min.js'),
jstree: path.resolve(__dirname, 'node_modules/jstree/dist/jstree.min.js'),
lazysizes: path.resolve(__dirname, 'node_modules/lazysizes/lazysizes.min.js'),
nanobar: path.resolve(__dirname, 'node_modules/nanobar/nanobar.min.js'),
'slick-carousel': path.resolve(__dirname, 'node_modules/slick-carousel/slick/slick.min.js'),
'svg-injector': path.resolve(__dirname, 'node_modules/svg-injector/dist/svg-injector.min.js'),
sweetalert2: path.resolve(__dirname, 'node_modules/sweetalert2/dist/sweetalert2.min.js'),
},
},
};