-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
37 lines (36 loc) · 1.29 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
function patchPostCSS(webpackConfig, tailwindConfig, components = false) {
if (!tailwindConfig) {
console.error('Missing tailwind config :', tailwindConfig)
return
}
const pluginName = 'autoprefixer'
for (const rule of webpackConfig.module.rules) {
if (!(rule.use && rule.use.length > 0) || (!components && rule.exclude)) {
continue
}
for (const useLoader of rule.use) {
if (!(useLoader.options && useLoader.options.postcssOptions)) {
continue
}
const originPostcssOptions = useLoader.options.postcssOptions
useLoader.options.postcssOptions = (loader) => {
const _postcssOptions = originPostcssOptions(loader)
const insertIndex = _postcssOptions.plugins.findIndex(
({ postcssPlugin }) => postcssPlugin && postcssPlugin.toLowerCase() === pluginName,
)
if (insertIndex !== -1) {
_postcssOptions.plugins.splice(insertIndex, 0, ['tailwindcss', tailwindConfig])
} else {
console.error(`${pluginName} not found in postcss plugins`)
}
return _postcssOptions
}
}
}
}
module.exports = (config) => {
const isProd = config.mode === 'production'
const tailwindConfig = require('./tailwind.config.js')(isProd)
patchPostCSS(config, tailwindConfig)
return config
}