From 6398b4879c57cc04c25d4b3114fe777b518bf0e9 Mon Sep 17 00:00:00 2001 From: Owen Buckley Date: Sat, 15 Oct 2022 12:15:50 -0400 Subject: [PATCH] Bug/leading slash in CSS (``) paths break bundling (#981) * normalize leading / for CSS bundling paths * update test cases * remove console logs --- packages/cli/src/lifecycles/bundle.js | 3 ++- .../build.default.workspace-javascript-css.spec.js | 10 ++++++++-- .../src/pages/index.html | 4 ++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/cli/src/lifecycles/bundle.js b/packages/cli/src/lifecycles/bundle.js index 1215cf54f..cdcb28834 100644 --- a/packages/cli/src/lifecycles/bundle.js +++ b/packages/cli/src/lifecycles/bundle.js @@ -65,10 +65,11 @@ async function bundleStyleResources(compilation, optimizationPlugins) { if (src) { const basename = path.basename(srcPath); const basenamePieces = path.basename(srcPath).split('.'); + const fileNamePieces = srcPath.split('/').filter(piece => piece !== ''); // normalize by removing any leading /'s optimizedFileName = srcPath.indexOf('/node_modules') >= 0 ? `${basenamePieces[0]}.${hashString(contents)}.css` - : srcPath.replace(basename, `${basenamePieces[0]}.${hashString(contents)}.css`); + : fileNamePieces.join('/').replace(basename, `${basenamePieces[0]}.${hashString(contents)}.css`); } else { optimizedFileName = `${hashString(contents)}.css`; } diff --git a/packages/cli/test/cases/build.default.workspace-javascript-css/build.default.workspace-javascript-css.spec.js b/packages/cli/test/cases/build.default.workspace-javascript-css/build.default.workspace-javascript-css.spec.js index 40ac4bc5e..888d75202 100644 --- a/packages/cli/test/cases/build.default.workspace-javascript-css/build.default.workspace-javascript-css.spec.js +++ b/packages/cli/test/cases/build.default.workspace-javascript-css/build.default.workspace-javascript-css.spec.js @@ -105,7 +105,9 @@ describe('Build Greenwood With: ', function() { it('should have one - +