-
-
Notifications
You must be signed in to change notification settings - Fork 422
Conversation
eb3faf8
to
bd02d86
Compare
As of bd02d86 I'm seeing lots of missing styles on svelte.dev in production builds when using this. |
For posterity: It was discovered that what is going on in production builds is that Terser is removing the diff --git a/src/core/create_compilers/RollupCompiler.ts b/src/core/create_compilers/RollupCompiler.ts
index 806dd7c..5939a0e 100644
--- a/src/core/create_compilers/RollupCompiler.ts
+++ b/src/core/create_compilers/RollupCompiler.ts
@@ -127,14 +127,14 @@ export default class RollupCompiler {
entry_point = inputs[0].file;
}
},
- renderChunk(code: string, chunk: RenderedChunk) {
+ renderChunk(code: string, chunk: RenderedChunk) {
that.chunks.push(chunk);
},
renderDynamicImport({ format, moduleId, targetModuleId, customResolution }) {
if (targetModuleId) {
return {
left: 'Promise.all([import(',
- right: `), /* ___${targetModuleId}___ */]).then(x => x[0])`
+ right: `), ___SAPPER___${Buffer.from(targetModuleId).toString('hex')}___]).then(x => x[0])`
};
} else {
return {
@@ -176,7 +176,8 @@ export default class RollupCompiler {
let chunk_has_css = false;
if (chunk.code) {
- chunk.code = chunk.code.replace(/\/\* ___(.+?)___ \*\//g, (m, id) => {
+ chunk.code = chunk.code.replace(/___SAPPER___([0-9a-f]+)___/g, (m, id) => {
+ id = Buffer.from(id, 'hex').toString();
const target = <OutputChunk>Object.values(bundle).find(c => (<OutputChunk>c).facadeModuleId === id);
if (target) {
@@ -190,7 +191,7 @@ export default class RollupCompiler {
}
}
- return m;
+ return '';
});
if (chunk_has_css) { edit: Fixed an issue where it was leaving the unknown global in the code if a chunk didn't have styles to inject. |
a6683d2
to
c3df855
Compare
a2eab5e
to
f52f150
Compare
(mod.plugins || (mod.plugins = [])).push({ | ||
// TODO this is hacky. refactor out into an external rollup plugin | ||
(mod.plugins || (mod.plugins = [])).push(css_chunks({ injectImports: true })); | ||
if (!JSON.stringify(mod.input).includes('client.')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My attention was drawn here because it was the line involved in the fix for Windows - and the new version of it makes me even more uncomfortable than the old version.
Why are we looking at JSON.stringify(mod.input)
? Are there multiple fields within mod.input
where this filename could occur? And is there a more precise regex we could use here, like /[\\/]client[\\/]client\.\w+\.js$/
or something?
edit: That regex won't work as-is if we continue to JSON.stringify()
because it won't catch the escaped backslashes, but I'm hoping that's something we can avoid doing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, this whole section is a bit icky. it wasn't the "TODO this is hacky" comment that brought your attention here? 😄
ok, I just updated it to be a bit better
I hope that we can refactor this out into an external plugin (either make it part of rollup-plugin-css-chunks
or a new one) very shortly which would make this go away
I'm trying to tidy this up a little bit by having |
I think the CSS code splitting stuff should be refactored out into an external Rollup plugin. Possibly made part of |
This has rollup inject css loading into the js files instead of putting it into
manifest-client
and having the application load it from there. Thanks to Rich for writing most of this code!