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

Add source map support #24

Merged
merged 2 commits into from
Sep 11, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Provide source map
fix #18
  • Loading branch information
znck committed Sep 11, 2016
commit 1587fc846330732807f86751d3f9cc6b9b749576
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"dependencies": {
"de-indent": "latest",
"html-minifier": "latest",
"magic-string": "^0.16.0",
"parse5": "latest",
"rollup-pluginutils": "latest",
"vue-template-compiler": "^2.0.0-rc.4",
Expand Down
14 changes: 11 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createFilter } from 'rollup-pluginutils';
import { writeFile } from 'fs';
import MagicString from 'magic-string';

import vueTransform from './vueTransform';
import DEFAULT_OPTIONS from './options';
Expand Down Expand Up @@ -106,18 +107,25 @@ export default function vue(options = {}) {
return null;
}

const { js, css } = vueTransform(source, id, options);
const { js, css, map } = vueTransform(source, id, options);

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

// Component javascript with inlined html template
return js;
return {
code: js,
map: map.generateMap({ hires: true }),
};
},
transformBundle(source) {
generateStyleBundle();
const map = new MagicString(source);

return source.replace(/if[\s]*\('__VUE_WITH_STATEMENT__'\)/g, 'with(this)');
return {
code: source.replace(/if[\s]*\('__VUE_WITH_STATEMENT__'\)/g, 'with(this)'),
map: map.generateMap({ hires: true }),
};
},
ongenerate(opts, rendered) {
generateStyleBundle();
Expand Down
11 changes: 9 additions & 2 deletions src/vueTransform.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import htmlMinifier from 'html-minifier';
import parse5 from 'parse5';
import validateTemplate from 'vue-template-validator';
import { relative } from 'path';
import MagicString from 'magic-string';

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

const map = new MagicString(script);

if (template) {
script = injectTemplate(script, template, lang);
} else if (render) {
script = injectRender(script, render, lang);
}
script = deIndent(script);

return script;
return {
code: script,
map,
};
}

export default function vueTransform(code, filePath, options) {
Expand Down Expand Up @@ -167,7 +173,8 @@ export default function vueTransform(code, filePath, options) {

// 5. Process script & style
return {
js,
js: js.code,
map: js.map,
css: nodes.style && {
content: parse5.serialize(nodes.style),
lang: checkLang(nodes.style),
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy