This repository has been archived by the owner on Apr 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
124 lines (117 loc) · 3.26 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
const autoprefixer = require('autoprefixer');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const path = require('path');
const url = require('url');
const webpack = require('webpack');
const BundleTracker = require('webpack-bundle-tracker');
const resolve = path.resolve.bind(path, __dirname);
const bundleTrackerPlugin = new BundleTracker({
filename: 'webpack-bundle.json'
});
const providePlugin = new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
Popper: 'popper.js',
'query-string': 'query-string'
});
module.exports = (_, argv) => {
const devMode = argv.mode !== 'production';
let extractCssPlugin;
let fileLoaderPath;
let output;
if (!devMode) {
const baseStaticPath = process.env.STATIC_URL || '/static/';
const publicPath = url.resolve(baseStaticPath, 'assets/');
output = {
path: resolve('saleor/static/assets/'),
filename: '[name].[chunkhash].js',
chunkFilename: '[name].[chunkhash].js',
publicPath: publicPath
};
fileLoaderPath = 'file-loader?name=[name].[hash].[ext]';
extractCssPlugin = new MiniCssExtractPlugin({
filename: '[name].[chunkhash].css',
chunkFilename: '[id].[chunkhash].css'
});
} else {
output = {
path: resolve('saleor/static/assets/'),
filename: '[name].js',
chunkFilename: '[name].js',
publicPath: '/static/assets/'
};
fileLoaderPath = 'file-loader?name=[name].[ext]';
extractCssPlugin = new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[name].css'
});
}
return {
entry: {
dashboard: './saleor/static/dashboard/js/dashboard.js',
document: './saleor/static/dashboard/js/document.js',
storefront: './saleor/static/js/storefront.js'
},
output: output,
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
sourceMap: true
}
},
{
loader: 'postcss-loader',
options: {
sourceMap: true,
plugins: function() {
return [autoprefixer];
}
}
},
{
loader: 'sass-loader',
options: {
sourceMap: true
}
}
]
},
{
test: /\.(eot|otf|png|svg|jpg|ttf|woff|woff2)(\?v=[0-9.]+)?$/,
loader: fileLoaderPath,
include: [
resolve('node_modules'),
resolve('saleor/static/fonts'),
resolve('saleor/static/images'),
resolve('saleor/static/dashboard/images')
]
}
]
},
optimization: {
removeAvailableModules: false,
removeEmptyChunks: false,
splitChunks: false
},
plugins: [bundleTrackerPlugin, extractCssPlugin, providePlugin],
resolve: {
alias: {
jquery: resolve('node_modules/jquery/dist/jquery.js')
},
extensions: ['.js', '.jsx']
},
devtool: 'sourceMap'
};
};