Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/leading slash in CSS (<link>) paths break bundling #981

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/cli/src/lifecycles/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ describe('Build Greenwood With: ', function() {
it('should have one <script> tag for non-module.js loaded in the <head>', function() {
const scriptTags = dom.window.document.querySelectorAll('head > script[src]');
const mainScriptTags = Array.prototype.slice.call(scriptTags).filter(script => {
return (/non-module.*[a-z0-9].js/).test(script.src);
const src = script.getAttribute('src');

return (/non-module.*[a-z0-9].js/).test(src) && src.indexOf('//') < 0;
});

expect(mainScriptTags.length).to.be.equal(1);
Expand Down Expand Up @@ -148,8 +150,12 @@ describe('Build Greenwood With: ', function() {
const linkTags = dom.window.document.querySelectorAll('head > link[rel="stylesheet"]');

expect(linkTags.length).to.be.equal(2);

linkTags.forEach(link => {
expect((/.*[a-z0-9].css/).test(link.href)).to.be.equal(true);
const href = link.getAttribute('href');
const hrefPieces = link.getAttribute('href').split('/');

expect(href).to.be.equal(`/styles/${hrefPieces[2]}`);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</style>

<link rel="stylesheet" href="../styles/main.css"></link>
<link href="../styles/other.css" rel="stylesheet"></link>
<link href="/styles/other.css" rel="stylesheet"></link>

<script type="module">
const two = 'script tag module inline two';
Expand Down Expand Up @@ -46,7 +46,7 @@
})
</script>

<script src="../scripts/non-module.js"></script>
<script src="/scripts/non-module.js"></script>
</head>

<body>
Expand Down