8000 fix(Quantum): Quantum CSS splitting respects hashing · fuse-box/fuse-box@eafee77 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Jun 20, 2023. It is now read-only.

Commit eafee77

Browse files
committed
fix(Quantum): Quantum CSS splitting respects hashing
1 parent 3e548cc commit eafee77

File tree

2 files changed

+48
-38
lines changed

2 files changed

+48
-38
lines changed

src/quantum/core/CSSCollection.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export class CSSCollection {
1212
private renderedFileName: string;
1313
public sourceMapsPath: string;
1414
public splitCSS: boolean;
15+
public written: boolean;
1516
constructor(public core: QuantumCore) {}
1617

1718
public add(css: CSSFile) {

src/quantum/plugin/BundleWriter.ts

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -112,43 +112,47 @@ export class BundleWriter {
112112
}
113113

114114
let index = 1;
115-
const writeBundle = (bundle: Bundle) => {
116-
return bundle.context.output.writeCurrent(bundle.generatedCode).then(output => {
117-
let entryString;
118-
if (bundle.quantumBit && bundle.quantumBit.entry) {
119-
entryString = bundle.quantumBit.entry.getFuseBoxFullPath();
120-
}
121-
bundleManifest[bundle.name] = {
122-
fileName: output.filename,
123-
hash: output.hash,
124-
type: "js",
125-
entry: entryString,
126-
absPath: output.path,
127-
webIndexed: !bundle.quantumBit,
128-
relativePath: output.relativePath,
129-
};
130-
// if this bundle belongs to splitting
131-
// we need to remember the generated file name and store
132-
// and then pass to the API
133-
if (bundle.quantumBit) {
134-
const splitOpts: any = [output.relativePath, bundle.quantumBit.entry.getID()];
135-
splitFileOptions.i[bundle.quantumBit.name] = splitOpts;
136-
if (bundle.quantumBit.cssCollection) {
137-
let cssName = bundle.quantumBit.name;
138-
if (!/\.css$/.test(cssName)) {
139-
cssName = `${cssName}.css`;
140-
}
141-
const splitConfig = this.core.context.quantumSplitConfig;
142-
if (bundle.quantumBit && splitConfig && splitConfig.resolveOptions) {
143-
const dest = splitConfig.getDest();
144-
cssName = joinFuseBoxPath(dest, cssName);
145-
}
146-
splitOpts.push({ css: true, name: cssName });
115+
const writeBundle = async (bundle: Bundle) => {
116+
const output = await bundle.context.output.writeCurrent(bundle.generatedCode);
117+
let entryString;
118+
if (bundle.quantumBit && bundle.quantumBit.entry) {
119+
entryString = bundle.quantumBit.entry.getFuseBoxFullPath();
120+
}
121+
bundleManifest[bundle.name] = {
122+
fileName: output.filename,
123+
hash: output.hash,
124+
type: "js",
125+
entry: entryString,
126+
absPath: output.path,
127+
webIndexed: !bundle.quantumBit,
128+
relativePath: output.relativePath,
129+
};
130+
// if this bundle belongs to splitting
131+
// we need to remember the generated file name and store
132+
// and then pass to the API
133+
if (bundle.quantumBit) {
134+
const splitOpts: any = [output.relativePath, bundle.quantumBit.entry.getID()];
135+
splitFileOptions.i[bundle.quantumBit.name] = splitOpts;
136+
const cssCollection = bundle.quantumBit.cssCollection;
137+
if (cssCollection) {
138+
let cssName = bundle.quantumBit.name;
139+
if (!/\.css$/.test(cssName)) {
140+
cssName = `${cssName}.css`;
141+
}
142+
const splitConfig = this.core.context.quantumSplitConfig;
143+
const output = await writeCSS(cssCollection, cssName);
144+
if (bundle.quantumBit && splitConfig && splitConfig.resolveOptions) {
145+
const dest = splitConfig.getDest();
146+
cssName = joinFuseBoxPath(dest, output.filename);
147147
}
148+
splitOpts.push({ css: true, name: cssName });
148149
}
149-
});
150+
}
150151
};
151152
const writeCSS = async (cssCollection: CSSCollection, key: string) => {
153+
if (cssCollection.written) {
154+
return;
155+
}
152156
const cssData = cssCollection.collection;
153157

154158
if (cssData.size > 0) {
@@ -194,13 +198,11 @@ export class BundleWriter {
19419 1E0A 8
if (useSourceMaps) {
195199
output.writeToOutputFolder(cssCollection.sourceMapsPath, cssCollection.sourceMap);
196200
}
201+
cssCollection.written = true;
202+
return cssResultData;
197203
}
198204
};
199205

200-
if (this.core.opts.shouldGenerateCSS()) {
201-
this.core.cssCollection.forEach(writeCSS);
202-
}
203-
204206
return each(producer.bundles, (bundle: Bundle) => {
205207
if (bundle.name === "api.js") {
206208
// has to be the highest priority
@@ -245,12 +247,19 @@ export class BundleWriter {
245247
if (this.core.opts.shouldUglify()) {
246248
this.uglifyBundle(bundle);
247249
}
248-
249250
await writeBundle(bundle);
250251
}
251252
}
252253
}
253254
})
255+
.then(async () => {
256+
if (this.core.opts.shouldGenerateCSS()) {
257+
for (const item of this.core.cssCollection) {
258+
const cssCollection = item[1];
259+
await writeCSS(cssCollection, item[0]);
260+
}
261+
}
262+
})
254263
.then(() => {
255264
const manifestPath = this.core.opts.getManifestFilePath();
256265
if (manifestPath) {

0 commit comments

Comments
 (0)
0