Skip to content

Commit 1b5cfa2

Browse files
committed
fix: move polyfill to enhancer to allow import
1 parent 4b731c4 commit 1b5cfa2

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

enhanceAppFiles.js

+8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
const path = require("path");
22
const vueLivePath = path.join(__dirname, "./vueLiveWithLayout");
3+
34
module.exports = function enhanceAppFiles() {
45
const content = [
56
// import live with es6 so that it is compatible with both build and dev
67
'import Vue from "vue";',
8+
// vuepress is compiled in both node and non-node models
9+
// it needs a "global" variable to make buble work.
10+
// one of its dependencies, buffer uses global to detect compat with browser
11+
// it is missing in browsers, so we add it.
12+
'if (typeof window !== "undefined" && window.global === undefined) {',
13+
" window.global = window;",
14+
"}",
715
// and in order for the loading to happen after we assign the variable,
816
// we load vue-live as a require instead of an import
917
`Vue.component("VueLive", () => import(${JSON.stringify(vueLivePath)}))`

vueLiveWithLayout.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
import layout from "vuepress-plugin-live/live-layout";
2-
3-
// vuepress is compiled in both node and non-node models
4-
// it needs a "global" variable to make buble work.
5-
// it is missing in browsers, so we add it.
6-
if (typeof window !== "undefined" && window.global === undefined) {
7-
window.global = {};
8-
}
9-
const { VueLive } = require("vue-live");
2+
import { VueLive } from "vue-live";
103

114
export default {
125
functional: true,

0 commit comments

Comments
 (0)