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

Commit 26bd9aa

Browse files
authored
Add source map support (#24)
* Compile .vue files without <template> section fix #18 * Provide source map fix #18
1 parent b7862c2 commit 26bd9aa

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"dependencies": {
3333
"de-indent": "latest",
3434
"html-minifier": "latest",
35+
"magic-string": "^0.16.0",
3536
"parse5": "latest",
3637
"rollup-pluginutils": "latest",
3738
"vue-template-compiler": "^2.0.0-rc.4",

src/index.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { createFilter } from 'rollup-pluginutils';
22
import { writeFile } from 'fs';
3+
import MagicString from 'magic-string';
34

45
import vueTransform from './vueTransform';
56
import DEFAULT_OPTIONS from './options';
@@ -106,18 +107,25 @@ export default function vue(options = {}) {
106107
return null;
107108
}
108109

109-
const { js, css } = vueTransform(source, id, options);
110+
const { js, css, map } = vueTransform(source, id, options);
110111

111112
// Map of every stylesheet
112113
styles[id] = css || {};
113114

114115
// Component javascript with inlined html template
115-
return js;
116+
return {
117+
code: js,
118+
map: map.generateMap({ hires: true }),
119+
};
116120
},
117121
transformBundle(source) {
118122
generateStyleBundle();
123+
const map = new MagicString(source);
119124

120-
return source.replace(/if[\s]*\('__VUE_WITH_STATEMENT__'\)/g, 'with(this)');
125+
return {
126+
code: source.replace(/if[\s]*\('__VUE_WITH_STATEMENT__'\)/g, 'with(this)'),
127+
map: map.generateMap({ hires: true }),
128+
};
121129
},
122130
ongenerate(opts, rendered) {
123131
generateStyleBundle();

src/vueTransform.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import htmlMinifier from 'html-minifier';
33
import parse5 from 'parse5';
44
import validateTemplate from 'vue-template-validator';
55
import { relative } from 'path';
6+
import MagicString from 'magic-string';
67

78
/**
89
* Check the lang attribute of a parse5 node.
@@ -125,14 +126,19 @@ function processScript(node, filePath, content, templateOrRender) {
125126
const before = padContent(content.slice(0, location));
126127
script = before + script;
127128

129+
const map = new MagicString(script);
130+
128131
if (template) {
129132
script = injectTemplate(script, template, lang);
130133
} else if (render) {
131134
script = injectRender(script, render, lang);
132135
}
133136
script = deIndent(script);
134137

135-
return script;
138+
return {
139+
code: script,
140+
map,
141+
};
136142
}
137143

138144
export default function vueTransform(code, filePath, options) {
@@ -167,7 +173,8 @@ export default function vueTransform(code, filePath, options) {
167173

168174
// 5. Process script & style
169175
return {
170-
js,
176+
js: js.code,
177+
map: js.map,
171178
css: nodes.style && {
172179
content: parse5.serialize(nodes.style),
173180
lang: checkLang(nodes.style),

0 commit comments

Comments
 (0)