feat: add enableSourcemap option

pull/6835/head
bluwy 5 years ago
parent 0d7c583364
commit d2c1e0eb02

@ -343,10 +343,16 @@ export default class Component {
? { code: null, map: null }
: result.css;
const jsSourcemapEnabled = compile_options.enableSourcemap === true || compile_options.enableSourcemap === 'js'
if (!jsSourcemapEnabled) {
js = print(program);
js.map = null;
} else {
const sourcemap_source_filename = get_sourcemap_source_filename(compile_options);
js = print(program, {
sourceMapSource: sourcemap_source_filename
sourceMapSource: sourcemap_source_filename,
});
js.map.sources = [
@ -359,6 +365,7 @@ export default class Component {
js.map = apply_preprocessor_sourcemap(sourcemap_source_filename, js.map, compile_options.sourcemap as (string | RawSourceMap | DecodedSourceMap));
}
}
return {
js,

@ -13,6 +13,7 @@ const valid_options = [
'name',
'filename',
'sourcemap',
'enableSourcemap',
'generate',
'errorMode',
'varsReport',
@ -82,7 +83,7 @@ function validate_options(options: CompileOptions, warnings: Warning[]) {
}
export default function compile(source: string, options: CompileOptions = {}) {
options = Object.assign({ generate: 'dom', dev: false }, options);
options = Object.assign({ generate: 'dom', dev: false, enableSourcemap: true }, options);
const stats = new Stats();
const warnings = [];

@ -34,9 +34,15 @@ export default function dom(
const css = component.stylesheet.render(options.filename, !options.customElement);
const cssSourcemapEnabled = options.enableSourcemap === true || options.enableSourcemap === 'css';
if (cssSourcemapEnabled) {
css.map = apply_preprocessor_sourcemap(options.filename, css.map, options.sourcemap as string | RawSourceMap | DecodedSourceMap);
} else {
css.map = null;
}
const styles = component.stylesheet.has_styles && options.dev
const styles = cssSourcemapEnabled && component.stylesheet.has_styles && options.dev
? `${css.code}\n/*# sourceMappingURL=${css.map.toUrl()} */`
: css.code;
@ -521,7 +527,7 @@ export default function dom(
constructor(options) {
super();
${css.code && b`this.shadowRoot.innerHTML = \`<style>${css.code.replace(/\\/g, '\\\\')}${options.dev ? `\n/*# sourceMappingURL=${css.map.toUrl()} */` : ''}</style>\`;`}
${css.code && b`this.shadowRoot.innerHTML = \`<style>${css.code.replace(/\\/g, '\\\\')}${cssSourcemapEnabled && options.dev ? `\n/*# sourceMappingURL=${css.map.toUrl()} */` : ''}</style>\`;`}
@init(this, { target: this.shadowRoot, props: ${init_props}, customElement: true }, ${definition}, ${has_create_fragment ? 'create_fragment' : 'null'}, ${not_equal}, ${prop_indexes}, null, ${dirty});

@ -200,11 +200,13 @@ export default function ssr(
main
].filter(Boolean);
const cssSourcemapEnabled = options.enableSourcemap === true || options.enableSourcemap === 'css';
const js = b`
${css.code ? b`
const #css = {
code: "${css.code}",
map: ${css.map ? string_literal(css.map.toString()) : 'null'}
map: ${cssSourcemapEnabled && css.map ? string_literal(css.map.toString()) : 'null'}
};` : null}
${component.extract_javascript(component.ast.module)}

@ -147,6 +147,7 @@ export interface CompileOptions {
varsReport?: 'full' | 'strict' | false;
sourcemap?: object | string;
enableSourcemap?: boolean | 'js' | 'css';
outputFilename?: string;
cssOutputFilename?: string;
sveltePath?: string;

Loading…
Cancel
Save