-
Notifications
You must be signed in to change notification settings - Fork 373
Expand file tree
/
Copy pathbundlerUtils.js
More file actions
37 lines (29 loc) · 1.02 KB
/
bundlerUtils.js
File metadata and controls
37 lines (29 loc) · 1.02 KB
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
// Returns the active bundler module per shakapacker.yml's `assets_bundler`.
// Supports both webpack and rspack so this project can switch between them
// without touching every config file.
const { config } = require('shakapacker');
let _cachedBundler = null;
const getBundler = () => {
if (_cachedBundler) {
return _cachedBundler;
}
_cachedBundler = config.assets_bundler === 'rspack' ? require('@rspack/core') : require('webpack');
return _cachedBundler;
};
const isRspack = () => config.assets_bundler === 'rspack';
// Only meaningful on rspack — webpack projects use mini-css-extract-plugin
// via shakapacker's generated config.
const getCssExtractPlugin = () => {
if (!isRspack()) {
throw new Error(
'getCssExtractPlugin() is only available when assets_bundler is rspack. ' +
"On webpack, rely on shakapacker's generated MiniCssExtractPlugin configuration.",
);
}
return getBundler().CssExtractRspackPlugin;
};
module.exports = {
getBundler,
isRspack,
getCssExtractPlugin,
};