-
Notifications
You must be signed in to change notification settings - Fork 738
/
Copy pathwebpack.config.base.js
157 lines (148 loc) · 3.98 KB
/
webpack.config.base.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
const path = require('node:path');
const { VueLoaderPlugin } = require('vue-loader');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const webpack = require('webpack');
module.exports = ({ mode = 'development', hot = false, cache = false, transpile = false } = {}) => {
const production = mode === 'production';
// Have to pass this option to prevent complaints about empty exports:
// https://github.com/vuejs/vue-loader/issues/1742#issuecomment-715294278
const cssInsertionLoader = hot
? 'style-loader'
: { loader: MiniCssExtractPlugin.loader, options: { esModule: false } };
const base_dir = path.join(__dirname, '..');
const postCSSLoader = {
loader: require.resolve('postcss-loader'),
options: {
postcssOptions: {
plugins: [[require.resolve('autoprefixer')]],
},
sourceMap: !production,
},
};
const cssLoader = {
loader: require.resolve('css-loader'),
options: { sourceMap: !production },
};
// for scss blocks
const sassLoaders = [
cssInsertionLoader,
cssLoader,
postCSSLoader,
require.resolve('sass-loader'),
];
const rules = [
// Transpilation and code loading rules
{
test: /\.vue$/,
loader: require.resolve('vue-loader'),
options: {
compilerOptions: {
preserveWhitespace: false,
},
},
},
{
test: /\.css$/,
use: [cssInsertionLoader, cssLoader, postCSSLoader],
},
{
test: /\.s[a|c]ss$/,
use: sassLoaders,
},
{
test: /\.(png|jpe?g|gif|svg|eot|woff|ttf|woff2)$/,
type: 'asset',
generator: {
filename: '[name]-[contenthash][ext]',
},
parser: {
dataUrlCondition: {
maxSize: 10000,
},
},
},
];
if (transpile) {
rules.push({
test: /\.(js|mjs)$/,
loader: require.resolve('babel-loader'),
exclude: [
// From: https://webpack.js.org/loaders/babel-loader/#exclude-libraries-that-should-not-be-transpiled
// \\ for Windows, / for macOS and Linux
/node_modules[\\/]core-js/,
/node_modules[\\/]webpack[\\/]buildin/,
],
options: {
cacheDirectory: cache,
cacheCompression: false,
},
});
}
return {
target: 'browserslist',
mode,
cache: cache && {
type: 'filesystem',
version: '1.0.0',
buildDependencies: {
config: [__filename],
},
},
module: {
rules,
},
node: {
__filename: true,
},
optimization: {
minimizer: [
new TerserPlugin({
parallel: true,
terserOptions: {
mangle: false,
safari10: true,
output: {
comments: false,
},
},
}),
new CssMinimizerPlugin({
minimizerOptions: {
preset: ['default', { reduceIdents: false, zindex: false }],
},
}),
],
},
resolve: {
extensions: ['.js', '.vue', '.scss'],
modules: [
// Add resolution paths for modules to allow any plugin to
// access kolibri-tools/node_modules modules during bundling.
base_dir,
path.join(base_dir, 'node_modules'),
],
},
resolveLoader: {
modules: [
// Add resolution paths for loaders to allow any plugin to
// access kolibri-tools/node_modules loaders during bundling.
base_dir,
path.join(base_dir, 'node_modules'),
],
},
plugins: [
new VueLoaderPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(mode),
'process.server': JSON.stringify(false),
}),
new webpack.ProvidePlugin({
process: require.resolve('process/browser'),
}),
],
devtool: production ? 'source-map' : 'cheap-module-source-map',
stats: production ? 'normal' : 'none',
};
};