-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathvite.config.js
More file actions
67 lines (61 loc) · 2.13 KB
/
Copy pathvite.config.js
File metadata and controls
67 lines (61 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import laravel from 'laravel-vite-plugin';
import * as Vue from 'vue';
// Statamic externals plugin - replaces Vue imports with window.Vue
// so addon shares the same Vue instance as the host app.
// Based on @statamic/cms/vite-plugin/externals.js
function statamicExternals() {
const RESOLVED_VIRTUAL_MODULE_ID = '\0vue-external';
const vueExports = Object.keys(Vue).filter(
key => key !== 'default' && /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key)
);
return {
name: 'statamic-externals',
enforce: 'pre',
resolveId(id) {
if (id === 'vue') return RESOLVED_VIRTUAL_MODULE_ID;
return null;
},
load(id) {
if (id === RESOLVED_VIRTUAL_MODULE_ID) {
const exportsList = vueExports.join(', ');
return `
const Vue = window.Vue;
export default Vue;
export const { ${exportsList} } = Vue;
`;
}
return null;
},
configResolved(resolvedConfig) {
resolvedConfig.build.rollupOptions.plugins = resolvedConfig.build.rollupOptions.plugins || [];
resolvedConfig.build.rollupOptions.plugins.push({
name: 'statamic-externals-renderchunk',
renderChunk(code) {
code = code.replace(
/import\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\s*,\s*(\{[^}]+\})\s+from\s+['"]vue['"];?/g,
'const $1 = window.Vue;\nconst $2 = window.Vue;'
);
return code.replace(
/import\s+(.+?)\s+from\s+['"]vue['"];?/g,
'const $1 = window.Vue;'
);
}
});
}
};
}
export default defineConfig({
plugins: [
laravel({
input: [
'resources/js/app.js',
'resources/css/app.css'
],
publicDirectory: 'resources/dist',
}),
statamicExternals(),
vue(),
],
});