@@ -108,9 +108,12 @@ afterAll(async () => {
108
108
} ) ;
109
109
110
110
111
- const defaultFiles = {
112
- '/vue3-sfc-loader.js' : Fs . readFileSync ( Path . join ( __dirname , '../dist/vue3-sfc-loader.js' ) , { encoding : 'utf-8' } ) ,
113
- '/vue' : Fs . readFileSync ( Path . join ( __dirname , '../node_modules/vue/dist/vue.global.js' ) , { encoding : 'utf-8' } ) ,
111
+ const defaultFilesFactory = ( { vueTarget } ) => ( {
112
+
113
+ [ `/vue${ vueTarget } -sfc-loader.js` ] : Fs . readFileSync ( Path . join ( __dirname , `../dist/vue${ vueTarget } -sfc-loader.js` ) , { encoding : 'utf-8' } ) ,
114
+
115
+ '/vue' : Fs . readFileSync ( Path . join ( __dirname , [ , , '../node_modules/vue2/dist/vue.runtime.js' , '../node_modules/vue/dist/vue.global.js' ] [ vueTarget ] ) , { encoding : 'utf-8' } ) ,
116
+
114
117
'/options.js' : `
115
118
116
119
class HttpError extends Error {
@@ -157,9 +160,12 @@ const defaultFiles = {
157
160
158
161
export default options;
159
162
` ,
163
+
164
+
160
165
'/optionsOverride.js' : `
161
166
export default () => {};
162
167
` ,
168
+
163
169
'/boot.js' : `
164
170
export default ({ options, createApp, mountApp }) => createApp(options).then(app => mountApp(app));
165
171
` ,
@@ -168,86 +174,67 @@ const defaultFiles = {
168
174
<!DOCTYPE html>
169
175
<html><body>
170
176
<script src="vue"></script>
171
- <script src="vue3 -sfc-loader.js"></script>
177
+ <script src="vue ${ vueTarget } -sfc-loader.js"></script>
172
178
<!-- scripts -->
173
179
<script type="module">
174
180
175
181
import boot from '/boot.js'
176
182
import options from '/options.js'
177
183
import optionsOverride from '/optionsOverride.js'
178
184
179
- const { loadModule } = window['vue3 -sfc-loader'];
185
+ const { loadModule } = window['vue ${ vueTarget } -sfc-loader'];
180
186
181
187
function createApp(options) {
182
188
183
- return loadModule('./component.vue', options).then((component) => Vue.createApp(component));
189
+ switch ( ${ vueTarget } ) {
190
+ case 3: {
191
+
192
+ return loadModule('./component.vue', options).then((component) => Vue.createApp(component));
193
+ }
194
+
195
+ case 2: {
196
+
197
+ return loadModule('./component.vue', options).then((component) => new Vue(component));
198
+ }
199
+ }
184
200
}
185
201
186
202
function mountApp(app, eltId = 'app') {
187
203
188
- if ( !document.getElementById(eltId) ) {
204
+ switch ( ${ vueTarget } ) {
205
+ case 3: {
189
206
190
- const parent = document.body;
191
- const elt = document.createElement('div');
192
- elt.id = eltId;
193
- parent.insertBefore(elt, parent.firstChild);
194
- }
207
+ if ( !document.getElementById(eltId) ) {
195
208
196
- return app.mount('#' + eltId);
197
- }
198
-
199
- optionsOverride(options)
209
+ const parent = document.body;
210
+ const elt = document.createElement('div');
211
+ elt.id = eltId;
212
+ parent.insertBefore(elt, parent.firstChild);
213
+ }
200
214
201
- boot({ options, createApp, mountApp, Vue })
202
- .then(app => app.$el.parentNode.vueApp = app);
215
+ return app.mount('#' + eltId);
216
+ }
203
217
204
- //window._done && window._done();
218
+ case 2: {
205
219
206
- </script>
207
- </body></html>
208
- `
209
- }
220
+ const mountElId = eltId + 'Mount';
210
221
211
- const defaultFilesVue2 = {
212
- '/vue2-sfc-loader.js' : Fs . readFileSync ( Path . join ( __dirname , '../dist/vue2-sfc-loader.js' ) , { encoding : 'utf-8' } ) ,
213
- '/vue' : Fs . readFileSync ( Path . join ( __dirname , '../node_modules/vue2/dist/vue.runtime.js' ) , { encoding : 'utf-8' } ) ,
214
- '/options.js' : defaultFiles [ '/options.js' ] ,
215
- '/optionsOverride.js' : defaultFiles [ '/optionsOverride.js' ] ,
216
- '/boot.js' : defaultFiles [ '/boot.js' ] ,
217
- '/index.html' : `
218
- <!DOCTYPE html>
219
- <html><body>
220
- <script src="vue"></script>
221
- <script src="vue2-sfc-loader.js"></script>
222
- <!-- scripts -->
223
- <script type="module">
224
-
225
- import boot from '/boot.js'
226
- import options from '/options.js'
227
- import optionsOverride from '/optionsOverride.js'
222
+ if ( !document.getElementById(mountElId) ) {
228
223
229
- const { loadModule } = window['vue2-sfc-loader'];
224
+ const parent = document.body;
225
+ const appElt = document.createElement('div');
226
+ appElt.id = eltId;
230
227
231
- function createApp(options) {
232
- return loadModule('./component.vue', options).then((component) => new Vue(component));
233
- }
228
+ const mountElt = document.createElement('div');
229
+ mountElt.id = mountElId;
234
230
235
- function mountApp(app, eltId = 'app') {
236
-
237
- const mountElId = eltId + 'Mount'
238
- if ( !document.getElementById(mountElId) ) {
239
- const parent = document.body;
240
- const appElt = document.createElement('div');
241
- appElt.id = eltId;
242
-
243
- const mountElt = document.createElement('div');
244
- mountElt.id = mountElId;
245
-
246
- appElt.insertBefore(mountElt, appElt.firstChild);
247
- parent.insertBefore(appElt, parent.firstChild);
248
- }
231
+ appElt.insertBefore(mountElt, appElt.firstChild);
232
+ parent.insertBefore(appElt, parent.firstChild);
233
+ }
249
234
250
- return app.$mount('#' + mountElId);
235
+ return app.$mount('#' + mountElId);
236
+ }
237
+ }
251
238
}
252
239
253
240
optionsOverride(options)
@@ -259,11 +246,11 @@ const defaultFilesVue2 = {
259
246
260
247
</script>
261
248
</body></html>
262
- `
263
- }
249
+ ` ,
250
+ } ) ;
251
+
264
252
265
253
module . exports = {
266
- defaultFiles,
267
- defaultFilesVue2,
254
+ defaultFilesFactory,
268
255
createPage,
269
256
}
0 commit comments