@@ -3,9 +3,10 @@ const Path = require('path');
3
3
const puppeteer = require ( 'puppeteer' ) ;
4
4
const mime = require ( 'mime-types' ) ;
5
5
6
-
7
6
const local = new URL ( 'http://local/' ) ;
8
7
8
+ const vueVersion = '3' ;
9
+
9
10
async function createPage ( { files } ) {
10
11
11
12
async function getFile ( url , encoding ) {
@@ -100,74 +101,75 @@ afterAll(async () => {
100
101
const defaultFiles = {
101
102
'/vue3-sfc-loader.js' : Fs . readFileSync ( Path . join ( __dirname , '../dist/vue3-sfc-loader.js' ) , { encoding : 'utf-8' } ) ,
102
103
'/vue' : Fs . readFileSync ( Path . join ( __dirname , '../node_modules/vue/dist/vue.global.js' ) , { encoding : 'utf-8' } ) ,
103
- '/boot.js' : `
104
104
105
- export default function boot({ options, createApp, mountApp }) {
105
+ '/options.js' : `
106
+
107
+ class HttpError extends Error {
108
+
109
+ constructor(url, res) {
106
110
107
- mountApp( createApp(options) );
111
+ super('HTTP error ' + res.statusCode);
112
+ Error.captureStackTrace(this, this.constructor);
113
+
114
+ // enumerable: default false
115
+ Object.defineProperties(this, {
116
+ name: {
117
+ value: this.constructor.name,
118
+ },
119
+ url: {
120
+ value: url,
121
+ },
122
+ res: {
123
+ value: res,
124
+ },
125
+ });
126
+ }
108
127
}
109
128
110
- ` ,
111
129
112
- '/index.html' : `
113
- <!DOCTYPE html>
114
- <html><body>
115
- <script src="vue"></script>
116
- <script src="vue3-sfc-loader.js"></script>
117
- <script type="module">
130
+ const options = {
118
131
119
- import boot from '/boot.js'
132
+ moduleCache: {
133
+ vue: Vue
134
+ },
120
135
121
- class HttpError extends Error {
122
-
123
- constructor(url, res) {
124
-
125
- super('HTTP error ' + res.statusCode);
126
- Error.captureStackTrace(this, this.constructor);
127
-
128
- // enumerable: default false
129
- Object.defineProperties(this, {
130
- name: {
131
- value: this.constructor.name,
132
- },
133
- url: {
134
- value: url,
135
- },
136
- res: {
137
- value: res,
138
- },
139
- });
140
- }
141
- }
136
+ getFile(path) {
142
137
138
+ return fetch(path).then(res => res.ok ? res.text() : Promise.reject(new HttpError(path, res)));
139
+ },
143
140
144
- const options = {
141
+ addStyle(textContent) {
145
142
146
- moduleCache: {
147
- vue: Vue
148
- },
143
+ const style = Object.assign(document.createElement('style'), { textContent });
144
+ const ref = document.head.getElementsByTagName('style')[0] || null;
145
+ document.head.insertBefore(style, ref);
146
+ },
149
147
150
- getFile(path ) {
148
+ log(type, ...args ) {
151
149
152
- return fetch(path).then(res => res.ok ? res.text() : Promise.reject(new HttpError(path, res)));
153
- },
150
+ console[type](...args);
151
+ }
152
+ }
154
153
155
- addStyle(textContent) {
154
+ export default options;
155
+ ` ,
156
156
157
- const style = Object.assign(document.createElement('style'), { textContent });
158
- const ref = document.head.getElementsByTagName('style')[0] || null;
159
- document.head.insertBefore(style, ref);
160
- },
157
+ '/boot.js' : `
158
+ export default ({ options, createApp, mountApp }) => mountApp( createApp(options) );
159
+ ` ,
161
160
162
- log(type, ...args) {
161
+ '/index.html' : `
162
+ <!DOCTYPE html>
163
+ <html><body>
164
+ <script src="vue"></script>
165
+ <script src="vue3-sfc-loader.js"></script>
166
+ <script type="module">
163
167
164
- console[type](...args);
165
- }
166
- }
168
+ import boot from '/boot.js'
169
+ import options from '/options.js'
167
170
168
171
const { loadModule } = window['vue3-sfc-loader'];
169
172
170
-
171
173
function createApp(options) {
172
174
173
175
return Vue.createApp(Vue.defineAsyncComponent( () => loadModule('./component.vue', options) ));
0 commit comments