Skip to content

Commit 9e69d77

Browse files
committed
💥 Fix API to allow correct URL resolution in hooks.
1 parent 449000f commit 9e69d77

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

src/index.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import * as atUrl from 'postcss-url';
99
import('postcss-url/src/type/custom');
1010

1111
export interface PostConfig {
12-
importResolve: (key: string, dir: string) => string | Promise<string>;
12+
importResolve: (importKey: string, baseKey: string) => string | Promise<string>;
1313
importLoad: (key: string) => string | Promise<string>;
14-
urlResolve: (key: string, isLocal: boolean) => string;
14+
urlResolve: (importKey: string, baseKey: string) => string;
1515
minify?: boolean;
1616
}
1717

@@ -25,10 +25,10 @@ export class PostBuilder {
2525
}
2626
}
2727

28-
build(key: string, baseKey: string) {
29-
return postcss(this.pluginList).process('@import "' + key + '"', {
28+
build(code: string, key: string) {
29+
return postcss(this.pluginList).process(code, {
3030
parser: safeParser,
31-
from: baseKey,
31+
from: key,
3232
map: {
3333
inline: false,
3434
sourcesContent: false
@@ -42,10 +42,9 @@ export class PostBuilder {
4242
load: this.config.importLoad
4343
}),
4444
atUrl({
45-
url: ((asset) => {
46-
const isLocal = !!asset.pathname;
47-
return this.config.urlResolve(isLocal ? asset.absolutePath! : asset.url, isLocal);
48-
}) as atUrl.CustomTransformFunction
45+
url: ((asset: any, dir: any, opts: any, decl: any) =>
46+
this.config.urlResolve(asset.url, decl.source.input.file)
47+
) as atUrl.CustomTransformFunction
4948
}),
5049
autoprefixer
5150
];

0 commit comments

Comments
 (0)