Skip to content
Merged
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
39 changes: 35 additions & 4 deletions MelteCompiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,15 @@ SvelteCompiler = class SvelteCompiler extends CachingCompiler {
if (Array.isArray(result)) {
result.forEach(section => size += section.data.length);
} else {
size = result.data.length + result.sourceMap.toString().length;
const { js, css } = result;

if (js && js.data) {
size += js.data.length + js.sourceMap.toString().length;
}

if (css && css.data) {
size += css.data.length + css.sourceMap.toString().length;
}
}

return size;
Expand Down Expand Up @@ -195,14 +203,21 @@ SvelteCompiler = class SvelteCompiler extends CachingCompiler {
file.addJavaScript({
path: file.getPathInPackage()
}, async () => {
return await getResult();
const { js, css } = await getResult();

if (css) {
file.addStylesheet(css);
}

return js;
});
}
}

async compileOneFile(file) {
// Search for head and body tags if lazy compilation isn't supported.
// Otherwise, the file has already been parsed in `compileOneFileLater`.

if (!file.supportsLazyCompilation) {
const sections = this.getHtmlSections(file);

Expand Down Expand Up @@ -379,7 +394,6 @@ SvelteCompiler = class SvelteCompiler extends CachingCompiler {
let compiledResult;
try {
compiledResult = this.svelte.compile(code, svelteOptions);

if (map) {
compiledResult.js.map = this.combineSourceMaps(map, compiledResult.js.map);
}
Expand All @@ -405,12 +419,29 @@ SvelteCompiler = class SvelteCompiler extends CachingCompiler {
);
}

let css;

if (svelteOptions.css === false && compiledResult.css) {
css = {
path: file.getPathInPackage(),
sourcePath: file.getPathInPackage(),
data: compiledResult.css.code,
sourceMap: compiledResult.css.map,
lazy: false
};
}

try {
return this.transpileWithBabel(
const js = this.transpileWithBabel(
compiledResult.js,
path,
file
);

return {
js,
css
}
} catch (e) {
// Throw unknown errors.
if (!e.start) {
Expand Down