Skip to content

Commit 7c146dd

Browse files
committed
fix: use vue-inbrowser-compiler
1 parent c4596c0 commit 7c146dd

14 files changed

+688
-1057
lines changed

package.json

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,18 @@
1212
"test:unit": "vue-cli-service test:unit"
1313
},
1414
"dependencies": {
15-
"acorn": "^6.1.1",
16-
"acorn-jsx": "^5.0.1",
17-
"buble": "^0.19.7",
1815
"lodash.debounce": "^4.0.8",
1916
"prismjs": "^1.16.0",
20-
"rewrite-imports": "^2.0.3",
2117
"vue": "^2.6.10",
22-
"vue-prism-editor": "^0.2.0",
23-
"vue-template-compiler": "^2.5.21",
24-
"walkes": "^0.2.1"
18+
"vue-inbrowser-compiler": "^3.13.8",
19+
"vue-prism-editor": "^0.2.0"
2520
},
2621
"devDependencies": {
27-
"@vue/cli-plugin-babel": "^3.6.0",
28-
"@vue/cli-plugin-e2e-cypress": "^3.7.0",
29-
"@vue/cli-plugin-eslint": "^3.6.0",
30-
"@vue/cli-plugin-unit-jest": "^3.6.3",
31-
"@vue/cli-service": "^3.6.0",
22+
"@vue/cli-plugin-babel": "^3.8.0",
23+
"@vue/cli-plugin-e2e-cypress": "^3.8.0",
24+
"@vue/cli-plugin-eslint": "^3.8.0",
25+
"@vue/cli-plugin-unit-jest": "^3.8.0",
26+
"@vue/cli-service": "^3.8.0",
3227
"@vue/test-utils": "1.0.0-beta.29",
3328
"babel-core": "7.0.0-bridge.0",
3429
"babel-eslint": "^10.0.1",
@@ -37,12 +32,12 @@
3732
"eslint": "^5.16.0",
3833
"eslint-plugin-vue": "^5.0.0",
3934
"raw-loader": "^2.0.0",
40-
"rollup": "^1.11.2",
35+
"rollup": "^1.12.4",
4136
"rollup-plugin-babel": "^4.3.2",
4237
"rollup-plugin-commonjs": "^9.3.4",
4338
"rollup-plugin-css-only": "^1.0.0",
4439
"rollup-plugin-json": "^4.0.0",
45-
"rollup-plugin-node-resolve": "^4.2.3",
40+
"rollup-plugin-node-resolve": "^5.0.0",
4641
"rollup-plugin-vue": "^5.0.0",
4742
"validate-commit-msg": "^2.14.0",
4843
"vuejs-datepicker": "^1.5.4"

src/Preview.vue

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
</template>
77

88
<script>
9-
import compileCode, { isCodeVueSfc } from "./utils/compileCode";
10-
import getVars from "./utils/getVars";
11-
import getVueConfigObject from "./utils/getVueConfigObject";
9+
import { compile, isCodeVueSfc } from "vue-inbrowser-compiler";
1210
import addScopedStyle from "./utils/addScopedStyle";
11+
import evalInContext from "./utils/evalInContext";
12+
import requireAtRuntime from "./utils/requireAtRuntime";
1313
1414
export default {
1515
name: "VueLivePreviewComponent",
@@ -69,21 +69,10 @@ export default {
6969
},
7070
renderComponent(code) {
7171
let data = {};
72-
let listVars = [];
73-
let script;
7472
let style;
75-
let template;
7673
try {
77-
const renderedComponent = compileCode(code);
74+
const renderedComponent = compile(code);
7875
style = renderedComponent.style;
79-
if (renderedComponent.html && renderedComponent.script.length) {
80-
// When it's a template preceeded by a script (vsg format)
81-
// NOTA: if it is an SFC, the html template will be added in the script
82-
83-
// extract all variable to set them up as data in the component
84-
// this way we can use in the template what is defined in the script
85-
listVars = getVars(renderedComponent.script);
86-
}
8776
if (renderedComponent.script) {
8877
// if the compiled code contains a script it might be "just" a script
8978
// if so, change scheme used by editor
@@ -93,14 +82,16 @@ export default {
9382
// it can be:
9483
// - a script setting up variables => we set up the data property of renderedComponent
9584
// - a `new Vue()` script that will return a full config object
96-
script = renderedComponent.script;
97-
data = getVueConfigObject(script, listVars, this.requires) || {};
85+
const script = renderedComponent.script;
86+
data =
87+
evalInContext(script, filepath =>
88+
requireAtRuntime(this.requires, filepath)
89+
) || {};
9890
}
99-
if (renderedComponent.html) {
91+
if (renderedComponent.template) {
10092
// if this is a pure template or if we are in hybrid vsg mode,
10193
// we need to set the template up.
102-
template = `<div>${renderedComponent.html}</div>`;
103-
data.template = template;
94+
data.template = `<div>${renderedComponent.template}</div>`;
10495
}
10596
} catch (e) {
10697
this.handleError(e);
@@ -116,6 +107,11 @@ export default {
116107
117108
if (data.template || data.render) {
118109
this.previewedComponent = data;
110+
} else {
111+
this.handleError({
112+
message:
113+
"[Vue Live] no template or render function specified, you might have an issue in your example"
114+
});
119115
}
120116
}
121117
}

src/utils/__tests__/compileCode.unit.js

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/utils/__tests__/getVars.unit.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/utils/__tests__/getVueConfigObject.unit.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/utils/__tests__/normalizeSfcComponent.unit.js

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/utils/__tests__/transformOneImport.unit.js

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/utils/compileCode.js

Lines changed: 0 additions & 59 deletions
This file was deleted.

src/utils/getAst.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)