Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit affa56c

Browse files
committed
Inject CSS loading with Rollup
1 parent 99cfc97 commit affa56c

File tree

10 files changed

+127
-317
lines changed

10 files changed

+127
-317
lines changed

package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"require-relative": "^0.8.7",
5858
"rollup": "^2.21.0",
5959
"rollup-dependency-tree": "0.0.14",
60+
"rollup-plugin-css-chunks": "^1.2.6",
6061
"rollup-plugin-svelte": "^5.1.0",
6162
"rollup-plugin-typescript2": "^0.27.1",
6263
"sade": "^1.6.1",

runtime/src/app/app.ts

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -359,27 +359,8 @@ export async function hydrate_target(dest: Target): Promise<HydratedTarget> {
359359
return { redirect, props, branch };
360360
}
361361

362-
function load_css(chunk: string) {
363-
const href = `client/${chunk}`;
364-
if (document.querySelector(`link[href="${href}"]`)) return;
365-
366-
return new Promise((fulfil, reject) => {
367-
const link = document.createElement('link');
368-
link.rel = 'stylesheet';
369-
link.href = href;
370-
371-
link.onload = () => fulfil();
372-
link.onerror = reject;
373-
374-
document.head.appendChild(link);
375-
});
376-
}
377-
378362
export function load_component(component: DOMComponentLoader): Promise<DOMComponentModule> {
379-
// TODO this is temporary — once placeholders are
380-
// always rewritten, scratch the ternary
381-
const promises: Array<Promise<any>> = (typeof component.css === 'string' ? [] : component.css.map(load_css));
382-
promises.unshift(component.js());
363+
const promises: Array<Promise<any>> = [component.js()];
383364
return Promise.all(promises).then(values => values[0]);
384365
}
385366

runtime/src/internal/manifest-client.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ export interface DOMComponentConstructor {
1919
}
2020

2121
export interface DOMComponentLoader {
22-
js: () => Promise<DOMComponentModule>,
23-
css: string[]
22+
js: () => Promise<DOMComponentModule>
2423
}
2524

2625
export interface Route {

src/api/build.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import minify_html from './utils/minify_html';
44
import { create_compilers, create_app, create_manifest_data, create_serviceworker_manifest } from '../core';
55
import { copy_shimport } from './utils/copy_shimport';
66
import read_template from '../core/read_template';
7-
import inject_resources from '../core/create_compilers/inject';
87
import { CompileResult } from '../core/create_compilers/interfaces';
98
import { noop } from './utils/noop';
109
import validate_bundler from './utils/validate_bundler';
@@ -103,16 +102,9 @@ export async function build({
103102
build_info.legacy_assets = legacy_client_result.assets;
104103
delete process.env.SAPPER_LEGACY_BUILD;
105104
}
106-
107105
fs.writeFileSync(path.join(dest, 'build.json'), JSON.stringify(build_info, null, ' '));
108-
if (bundler === 'rollup') {
109-
inject_resources(path.join(dest, 'build.json'), path.join(dest, 'client'));
110-
}
111106

112107
const server_stats = await server.compile();
113-
if (bundler === 'rollup') {
114-
inject_resources(path.join(dest, 'build.json'), path.join(dest, 'server'));
115-
}
116108
oncompile({
117109
type: 'server',
118110
result: server_stats

src/api/dev.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import * as ports from 'port-authority';
66
import { EventEmitter } from 'events';
77
import { create_manifest_data, create_app, create_compilers, create_serviceworker_manifest } from '../core';
88
import { Compiler, Compilers } from '../core/create_compilers';
9-
import inject_resources from '../core/create_compilers/inject';
109
import { CompileResult } from '../core/create_compilers/interfaces';
1110
import Deferred from './utils/Deferred';
1211
import validate_bundler from './utils/validate_bundler';
@@ -233,10 +232,6 @@ class Watcher extends EventEmitter {
233232
this.restart(filename, 'server');
234233
},
235234

236-
// Note that we don't inject the CSS path into the server in dev mode, which means
237-
// that styles might not work if you have JavaScript disabled. We skip it because if
238-
// the server completes before the client it will fail to find build.json. This is not
239-
// an issue for production builds because we don't have two simultaneous watchers then.
240235
handle_result: (result: CompileResult) => {
241236
deferred.promise.then(() => {
242237
const restart = () => {
@@ -341,10 +336,6 @@ class Watcher extends EventEmitter {
341336
JSON.stringify(result.to_json(manifest_data, this.dirs), null, ' ')
342337
);
343338

344-
if (this.bundler === 'rollup') {
345-
inject_resources(path.join(this.dirs.dest, 'build.json'), path.join(this.dirs.dest, 'client'));
346-
}
347-
348339
const client_files = result.chunks.map(chunk => `client/${chunk.file}`);
349340

350341
create_serviceworker_manifest({

src/core/create_app.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ function generate_client_manifest(
102102
component_indexes[component.name] = i;
103103
104104
return `{
105-
js: () => import(${annotation}${stringify(source)}),
106-
css: "__SAPPER_CSS_PLACEHOLDER:${stringify(component.file, false)}__"
105+
js: () => import(${annotation}${stringify(source)})
107106
}`;
108107
}).join(',\n\t\t\t\t')}
109108
]`.replace(/^\t/gm, '');

0 commit comments

Comments
 (0)