Use relative source paths

pull/1863/head
Timothy Johnson 7 years ago
parent b251c574eb
commit 3e8452d26d

@ -7,6 +7,7 @@ import renderSSR from './render-ssr/index';
import { CompileOptions, Warning, Ast } from '../interfaces';
import Component from './Component';
import deprecate from '../utils/deprecate';
import { relative } from 'path';
function normalize_options(options: CompileOptions): CompileOptions {
let normalized = assign({ generate: 'dom', dev: false }, options);
@ -93,13 +94,24 @@ export default function compile(source: string, options: CompileOptions = {}) {
const result = renderDOM(component, options);
if (options.sourceMap) {
const cwd = process.cwd();
const inputConsumer = new SourceMapConsumer(options.sourceMap);
const jsSourceMap = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(result.js.map));
result.js.map.sources = result.js.map.sources.map(file =>
relative(cwd, file)
);
const jsSourceMap = SourceMapGenerator.fromSourceMap(
new SourceMapConsumer(result.js.map)
);
jsSourceMap.applySourceMap(inputConsumer);
result.js.map = jsSourceMap.toJSON();
const cssSourceMap = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(result.css.map));
result.css.map.sources = result.css.map.sources.map(file =>
relative(cwd, file)
);
const cssSourceMap = SourceMapGenerator.fromSourceMap(
new SourceMapConsumer(result.css.map)
);
cssSourceMap.applySourceMap(inputConsumer);
result.css.map = cssSourceMap.toJSON();
}

@ -1,6 +1,7 @@
import { SourceMap } from 'magic-string';
import { SourceMapConsumer, SourceMapGenerator } from 'source-map';
import getCodeFrame from '../utils/getCodeFrame.js';
import { relative } from 'path';
export interface PreprocessOptions {
markup?: (options: {
@ -92,7 +93,9 @@ async function replaceTagContents(
if (processed.map) {
const consumer = new SourceMapConsumer(processed.map);
const generator = new SourceMapGenerator({ file: options.filename });
const generator = new SourceMapGenerator({
file: relative(process.cwd(), options.filename),
});
consumer.eachMapping(mapping => {
generator.addMapping({
source: mapping.source,
@ -169,7 +172,9 @@ export default async function preprocess(
}
}
let allMaps = new SourceMapGenerator({ file: options.filename });
let allMaps = new SourceMapGenerator({
file: relative(process.cwd(), options.filename),
});
if (!!style) {
const { code, map } = await replaceTagContents(source, 'style', style, options);

Loading…
Cancel
Save