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

Commit b2c670c

Browse files
committedOct 20, 2016
Add debug output
1 parent 6492485 commit b2c670c

File tree

5 files changed

+37
-8
lines changed

5 files changed

+37
-8
lines changed
 

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"homepage": "https://github.com/znck/rollup-plugin-vue#readme",
3232
"dependencies": {
3333
"de-indent": "^1.0.2",
34+
"debug": "^2.2.0",
3435
"html-minifier": "^3.1.0",
3536
"magic-string": "^0.16.0",
3637
"parse5": "^2.2.2",

‎src/debug.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import debug from 'debug';
2+
3+
export default debug('rollup-plugin-vue');

‎src/index.js

+24-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import MagicString from 'magic-string';
44

55
import vueTransform from './vueTransform';
66
import DEFAULT_OPTIONS from './options';
7+
import debug from './debug';
78

89
function mergeOptions(options, defaults) {
910
Object.keys(defaults).forEach((key) => {
@@ -22,6 +23,7 @@ function mergeOptions(options, defaults) {
2223
}
2324

2425
export default function vue(options = {}) {
26+
debug('Yo! rolling vue!');
2527
const filter = createFilter(options.include, options.exclude);
2628

2729
delete options.include;
@@ -32,6 +34,7 @@ export default function vue(options = {}) {
3234
const vueVersion = require('vue').version;
3335
if (parseInt(vueVersion.split('.')[0], 10) >= 2) {
3436
if (!('compileTemplate' in options)) {
37+
debug('Vue 2.0 detected. Compiling template.');
3538
options.compileTemplate = true;
3639
}
3740
} else {
@@ -47,14 +50,15 @@ export default function vue(options = {}) {
4750
options = mergeOptions(options, DEFAULT_OPTIONS);
4851

4952
const styles = {};
50-
let rollupOptions = {};
53+
let rollupOptions;
5154
let generated = false;
5255
const generateStyleBundle = () => {
5356
if (options.css === false) {
5457
return;
5558
}
5659

5760
if (generated) {
61+
debug('Style already generated!');
5862
return;
5963
}
6064

@@ -99,38 +103,51 @@ export default function vue(options = {}) {
99103
return {
100104
name: 'vue',
101105
options(o) {
102-
rollupOptions = o;
103-
return o;
106+
if (rollupOptions === undefined) {
107+
rollupOptions = o;
108+
debug('Set options.');
109+
}
104110
},
105111
transform(source, id) {
106112
if (!filter(id) || !id.endsWith('.vue')) {
113+
debug(`Ignore: ${id}`);
107114
return null;
108115
}
109116

117+
debug(`Transform: ${id}`);
110118
const { js, css, map } = vueTransform(source, id, options);
111119

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

115123
// Component javascript with inlined html template
116-
return {
124+
const result = {
117125
code: js,
118126
map: map.generateMap({ hires: true }),
119127
};
128+
129+
debug(`Transformed: ${id}`);
130+
131+
return result;
120132
},
121133
transformBundle(source) {
134+
debug('Replace window.__VUE_WITH_STATEMENT__ with with(this) and generate style.');
122135
generateStyleBundle();
123136
const map = new MagicString(source);
124-
125-
return {
137+
const result = {
126138
code: source.replace(/if[\s]*\(window\.__VUE_WITH_STATEMENT__\)/g, 'with(this)'),
127139
map: map.generateMap({ hires: true }),
128140
};
141+
debug('with(this) fixed!');
142+
143+
return result;
129144
},
130145
ongenerate(opts, rendered) {
146+
debug('on generate!');
131147
generateStyleBundle();
132148
rendered.code = rendered.code.replace(
133-
/if[\s]*\(window\.__VUE_WITH_STATEMENT__\)/g, 'with(this)');
149+
/if[\s]*\(window\.__VUE_WITH_STATEMENT__\)/g, 'with(this)');
150+
debug('with(this) fixed!');
134151
},
135152
};
136153
}

‎src/vueTransform.js

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import parse5 from 'parse5';
44
import validateTemplate from 'vue-template-validator';
55
import { relative } from 'path';
66
import MagicString from 'magic-string';
7+
import debug from './debug';
78

89
/**
910
* Check the lang attribute of a parse5 node.
@@ -68,6 +69,8 @@ function injectRender(script, render, lang) {
6869
`${render.staticRenderFns.map(wrapRenderFunction).join(',')}],`
6970
);
7071
}
72+
73+
debug(`No injection location found in: \n${script}\n`);
7174
}
7275
throw new Error('[rollup-plugin-vue] could not find place to inject template in script.');
7376
}
@@ -85,6 +88,8 @@ function injectTemplate(script, template, lang) {
8588
return script.split(matches[1])
8689
.join(`${matches[1]} template: ${JSON.stringify(template)},`);
8790
}
91+
92+
debug(`No injection location found in: \n${script}\n`);
8893
}
8994
throw new Error('[rollup-plugin-vue] could not find place to inject template in script.');
9095
}
@@ -137,7 +142,10 @@ function processScript(node, filePath, content, templateOrRender) {
137142
script = injectTemplate(script, template, lang);
138143
} else if (render) {
139144
script = injectRender(script, render, lang);
145+
} else {
146+
debug('Nothing to inject!');
140147
}
148+
141149
script = deIndent(script);
142150

143151
return {

‎yarn.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ de-indent, de-indent@^1.0.2:
414414
version "1.0.2"
415415
resolved "https://registry.yarnpkg.com/de-indent/-/de-indent-1.0.2.tgz#b2038e846dc33baa5796128d0804b455b8c1e21d"
416416

417-
debug@*, debug@^2.1.1, debug@^2.2.0, debug@2.2.0:
417+
debug, debug@*, debug@^2.1.1, debug@^2.2.0, debug@2.2.0:
418418
version "2.2.0"
419419
resolved "https://registry.yarnpkg.com/debug/-/debug-2.2.0.tgz#f87057e995b1a1f6ae6a4960664137bc56f039da"
420420
dependencies:

0 commit comments

Comments
 (0)