-
Notifications
You must be signed in to change notification settings - Fork 22
/
webpack.config.js
47 lines (38 loc) · 1.45 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
// You can extend default webpack build here.
// Read more in docs: https://github.com/DivanteLtd/vue-storefront/blob/master/docs/guide/core-themes/webpack.md
const merge = require('webpack-merge');
const themeRoot = require('@vue-storefront/core/build/theme-path');
function addPostCSSPlugin (loader, plugin) {
const plugins = loader.options.plugins instanceof Function
? loader.options.plugins()
: loader.options.plugins;
plugins.push(plugin);
loader.options.plugins = loader.options.plugins instanceof Function
? () => plugins
: plugins;
}
/**
* Traverses webpack's module rules to find all PostCSS loaders. For each PostCSS loader
* the 'postcss-flexbugs-fixes' plugin has to be found and it has to be configured to skip
* @storefront-ui library from being processed.
*
* @param {object} rules
*/
function fixPostCSSPlugins (rules) {
const processedLoaders = [];
rules.forEach(rule => {
const loader = rule.use ? rule.use.find(item => item.loader === 'postcss-loader') : null;
if (loader && !processedLoaders.includes(loader)) {
addPostCSSPlugin(loader, require('tailwindcss')(`${themeRoot}/tailwind.config.js`));
processedLoaders.push(loader);
}
});
}
module.exports = function (config, { isClient }) {
const mergedConfig = merge(
{ resolve: { alias: { 'src/modules/client': `${themeRoot}/config/modules` } } },
config
);
fixPostCSSPlugins(mergedConfig.module.rules);
return mergedConfig;
};