Skip to content

Commit 2eb2693

Browse files
author
liuqi
committed
fix: 修正postcss-loader 的插入位置;
1 parent ce924aa commit 2eb2693

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

lib/core/loader.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ module.exports = {
262262
}
263263
});
264264
if (this.postcss && itemLoader.postcss) {
265-
const postcssIndex = ['css', 'css_module'].includes(name) ? itemLoader.use.length : itemLoader.use.length - 1;
265+
const cssIndex = this.utils.getLoaderIndex(itemLoader.use, 'css-loader');
266+
const postcssIndex = cssIndex ? cssIndex : this.utils.getLoaderIndex(itemLoader.use, 'style-loader');
266267
const postcssLoader = this.createPostCssLoader(loaderOptions && loaderOptions.postcss);
267268
itemLoader.use.splice(postcssIndex, 0, postcssLoader);
268269
}

utils/utils.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ utils.joinPath = function() {
8181
}).join('/');
8282
};
8383

84+
utils.getLoaderIndex = (loaders, loaderName) => {
85+
return loaders.findIndex(loader => loaderName === (utils.isObject(loader) ? loader.loader : loader)) + 1;
86+
}
87+
8488
utils.getOutputPath = config => {
8589
const { output = {}, buildPath } = config;
8690
if (output.path) {

0 commit comments

Comments
 (0)