Skip to content

Commit f8905b3

Browse files
committed
fix(createVueInstance): not working slots in production build
1 parent 80ef843 commit f8905b3

File tree

2 files changed

+42
-63
lines changed

2 files changed

+42
-63
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"scripts": {
2121
"dev": "rollup -wm -c build/dev.config.rollup.js",
2222
"dev:demo": "node build/dev-server.js",
23-
"build": "node build/build.rollup.js && npm run build:demo",
23+
"build": "npm run build:library && npm run build:demo",
24+
"build:library": "node build/build.rollup.js",
2425
"build:demo": "node build/build-demo.js",
2526
"e2e": "node test/e2e/runner.js",
2627
"test": "npm run e2e",

src/utils/createVueInstance.js

Lines changed: 40 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -32,71 +32,49 @@ export default function createVueInstance(element, Vue, componentDefinition, pro
3232
/**
3333
* Developement ENV - will be removed in production build
3434
*/
35-
if (process.env.NODE_ENV === 'development') {
36-
if (vueVersion >= 2) {
37-
const elementOriginalChildren = element.cloneNode(true).childNodes; // clone hack due to IE compatibility
38-
// Vue 2+
39-
rootElement = {
40-
propsData,
41-
props: props.camelCase,
42-
computed: {
43-
reactiveProps() {
44-
const reactivePropsList = {};
45-
props.camelCase.forEach((prop) => {
46-
reactivePropsList[prop] = this[prop];
47-
});
35+
if (vueVersion >= 2) {
36+
const elementOriginalChildren = element.cloneNode(true).childNodes; // clone hack due to IE compatibility
37+
// Vue 2+
38+
rootElement = {
39+
propsData,
40+
props: props.camelCase,
41+
computed: {
42+
reactiveProps() {
43+
const reactivePropsList = {};
44+
props.camelCase.forEach((prop) => {
45+
reactivePropsList[prop] = this[prop];
46+
});
4847

49-
return reactivePropsList;
50-
}
51-
},
52-
/* eslint-disable */
53-
render(createElement) {
54-
const data = {
55-
props: this.reactiveProps
56-
};
57-
58-
return createElement(
59-
ComponentDefinition,
60-
data,
61-
getSlots(elementOriginalChildren, createElement)
62-
);
48+
return reactivePropsList;
6349
}
64-
/* eslint-enable */
65-
};
66-
} else if (vueVersion === 1) {
67-
// Fallback for Vue 1.x
68-
rootElement = ComponentDefinition;
69-
rootElement.propsData = propsData;
70-
} else {
71-
// Fallback for older Vue versions
72-
rootElement = ComponentDefinition;
73-
const propsWithDefault = {};
74-
Object.keys(propsData)
75-
.forEach((prop) => {
76-
propsWithDefault[prop] = { default: propsData[prop] };
77-
});
78-
rootElement.props = propsWithDefault;
79-
}
80-
}
50+
},
51+
/* eslint-disable */
52+
render(createElement) {
53+
const data = {
54+
props: this.reactiveProps
55+
};
8156

82-
/**
83-
* Production ENV
84-
*/
85-
if (process.env.NODE_ENV === 'production') {
86-
if (vueVersion >= 1) {
87-
// Fallback for Vue 1.x
88-
rootElement = ComponentDefinition;
89-
rootElement.propsData = propsData;
90-
} else {
91-
// Fallback for older Vue versions
92-
rootElement = ComponentDefinition;
93-
const propsWithDefault = {};
94-
Object.keys(propsData)
95-
.forEach((prop) => {
96-
propsWithDefault[prop] = { default: propsData[prop] };
97-
});
98-
rootElement.props = propsWithDefault;
99-
}
57+
return createElement(
58+
ComponentDefinition,
59+
data,
60+
getSlots(elementOriginalChildren, createElement)
61+
);
62+
}
63+
/* eslint-enable */
64+
};
65+
} else if (vueVersion === 1) {
66+
// Fallback for Vue 1.x
67+
rootElement = ComponentDefinition;
68+
rootElement.propsData = propsData;
69+
} else {
70+
// Fallback for older Vue versions
71+
rootElement = ComponentDefinition;
72+
const propsWithDefault = {};
73+
Object.keys(propsData)
74+
.forEach((prop) => {
75+
propsWithDefault[prop] = { default: propsData[prop] };
76+
});
77+
rootElement.props = propsWithDefault;
10078
}
10179

10280
const componentRootElement = document.createElement('div');

0 commit comments

Comments
 (0)