Skip to content

Commit cff0e8e

Browse files
committed
fix namer
1 parent b92ce0b commit cff0e8e

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

lib/loader.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function getLoadFilePrefix(loaderContext) {
2626
return `-!${require.resolve('./stringifyLoader')}!${loadersRequest}!`;
2727
}
2828

29-
function loader(src) {
29+
function loader(src, prevMap, meta) {
3030
const { resourcePath, _compilation: compilation } = this;
3131
const cb = this.async();
3232
const fs = this._compilation.inputFileSystem;
@@ -51,7 +51,6 @@ function loader(src) {
5151
};
5252

5353
const loadFile = promisify((file, done) => {
54-
// console.log('LOAD FILE');
5554
if (compilation[CACHE].has(file)) {
5655
done(null, compilation[CACHE].get(file));
5756
return;
@@ -86,6 +85,9 @@ function loader(src) {
8685
}
8786

8887
compat = compat.map(([, plugin]) => plugin);
88+
// spread this out now, b/c sometimes the namer runs later after the context
89+
// is in a weird spot and it's getters don't work anymore
90+
const namerContext = { ...this };
8991

9092
const mCssOptions = {
9193
exportGlobals: false,
@@ -96,10 +98,9 @@ function loader(src) {
9698
rewrite: false,
9799
resolvers: [resolver, ...(options.resolvers || [])],
98100
namer: (filename, localName) =>
99-
getLocalName(filename, localName, this, options),
100-
before: compat
101-
.filter((p) => p.phase === 'before')
102-
.concat(options.before)
101+
getLocalName(filename, localName, namerContext, options),
102+
before: [options.before]
103+
.concat(compat.filter((p) => p.phase === 'before'))
103104
.filter(Boolean),
104105
processing: []
105106
.concat(compat.filter((p) => p.phase === 'processing'))
@@ -112,7 +113,19 @@ function loader(src) {
112113

113114
const processor = compilation[PROCESSOR];
114115

115-
return processor.string(resourcePath, src).then(
116+
let root;
117+
if (meta) {
118+
const { ast } = meta;
119+
if (ast && ast.type === 'postcss') {
120+
root = ast.root;
121+
}
122+
}
123+
124+
const processing = root
125+
? processor.root(resourcePath, root)
126+
: processor.string(resourcePath, src);
127+
128+
return processing.then(
116129
({ details }) => {
117130
const { result } = details;
118131

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
"postcss": "^7.0.27",
8383
"postcss-selector-parser": "^6.0.2",
8484
"sass-loader": "^8.0.2",
85+
"semver": "^7.3.2",
8586
"webpack": "^4.43.0"
8687
},
8788
"bugs": {

0 commit comments

Comments
 (0)