forked from tastejs/angular-movies
/
webpack.config.js
59 lines (58 loc) · 2.08 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
function patchWebpackPostcssPlugins({
webpackConfig,
addPlugins = [],
pluginName = null,
append = false,
atIndex = null,
components = true,
global = true,
}) {
const position = append ? 1 : 0;
webpackConfig.module.rules.map((rule) => {
if (!(rule.use && rule.use.length > 0) || (!components && rule.exclude) || (!global && rule.include)) {
return rule;
}
rule.use.map((useLoader) => {
if (!(useLoader.options && useLoader.options.postcssOptions)) {
return useLoader;
}
const postcssOptions = useLoader.options.postcssOptions;
useLoader.options.postcssOptions = (loader) => {
const _postcssOptions = postcssOptions(loader);
const pluginIndex =
atIndex !== null
? atIndex
: _postcssOptions.plugins.findIndex(
({ postcssPlugin }) =>
postcssPlugin && pluginName && postcssPlugin.toLowerCase() === pluginName.toLowerCase()
);
if (pluginName && pluginIndex === -1) {
console.warn(`${pluginName} not found in postcss plugins`);
}
console.log('pluginName', pluginName);
const insertIndex =
pluginIndex >= 0
? Math.min(Math.max(pluginIndex, 0), _postcssOptions.plugins.length)
: _postcssOptions.plugins.length;
_postcssOptions.plugins.splice(insertIndex + position, 0, ...addPlugins);
return _postcssOptions;
};
return useLoader;
});
return rule;
});
}
module.exports = (config) => {
const csso = require('postcss-csso');
patchWebpackPostcssPlugins({
webpackConfig: config,
addPlugins: [],
// pluginName: "autoprefixer",
// global: false,
// components: false,
// atIndex: 2,
// append: false,
});
console.info('CSSO', config);
return config;
};