From 13e64508abad52b0d774ed7a5f30d78cff86819c Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Mon, 25 Jul 2022 21:06:38 +1000 Subject: [PATCH] fix: normalise css paths in manifest on windows (fixes #9295) (#9353) Co-authored-by: sapphi-red --- packages/vite/src/node/plugins/css.ts | 4 +++- .../backend-integration/__tests__/backend-integration.spec.ts | 2 ++ playground/backend-integration/dir/foo.css | 3 +++ playground/backend-integration/vite.config.js | 1 + 4 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 playground/backend-integration/dir/foo.css diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index b4429961ef479a..b2df2df9f7f0a5 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -519,7 +519,9 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { } function ensureFileExt(name: string, ext: string) { - return path.format({ ...path.parse(name), base: undefined, ext }) + return normalizePath( + path.format({ ...path.parse(name), base: undefined, ext }) + ) } if (config.build.cssCodeSplit) { diff --git a/playground/backend-integration/__tests__/backend-integration.spec.ts b/playground/backend-integration/__tests__/backend-integration.spec.ts index f0589783cbecf8..a6b773bf791ddb 100644 --- a/playground/backend-integration/__tests__/backend-integration.spec.ts +++ b/playground/backend-integration/__tests__/backend-integration.spec.ts @@ -35,6 +35,7 @@ describe.runIf(isBuild)('build', () => { const cssAssetEntry = manifest['global.css'] const scssAssetEntry = manifest['nested/blue.scss'] const imgAssetEntry = manifest['../images/logo.png'] + const dirFooAssetEntry = manifest['../../dir/foo.css'] // '\\' should not be used even on windows expect(htmlEntry.css.length).toEqual(1) expect(htmlEntry.assets.length).toEqual(1) expect(cssAssetEntry?.file).not.toBeUndefined() @@ -44,6 +45,7 @@ describe.runIf(isBuild)('build', () => { expect(scssAssetEntry?.isEntry).toEqual(true) expect(imgAssetEntry?.file).not.toBeUndefined() expect(imgAssetEntry?.isEntry).toBeUndefined() + expect(dirFooAssetEntry).not.toBeUndefined() }) }) diff --git a/playground/backend-integration/dir/foo.css b/playground/backend-integration/dir/foo.css new file mode 100644 index 00000000000000..c2fad7486d3ab6 --- /dev/null +++ b/playground/backend-integration/dir/foo.css @@ -0,0 +1,3 @@ +.windows-path-foo { + color: blue; +} diff --git a/playground/backend-integration/vite.config.js b/playground/backend-integration/vite.config.js index b8bfa70bb43112..ce3f3361fc70d1 100644 --- a/playground/backend-integration/vite.config.js +++ b/playground/backend-integration/vite.config.js @@ -19,6 +19,7 @@ function BackendIntegrationExample() { .map((filename) => [path.relative(root, filename), filename]) entrypoints.push(['tailwindcss-colors', 'tailwindcss/colors.js']) + entrypoints.push(['foo.css', path.resolve(__dirname, './dir/foo.css')]) return { build: {