-
-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathgenerate-vite-config.js
More file actions
89 lines (84 loc) · 2.46 KB
/
generate-vite-config.js
File metadata and controls
89 lines (84 loc) · 2.46 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const indent = require('../utils/indent');
const templateIf = require('../utils/template-if');
module.exports = (options) => {
const { framework, type, cordova } = options;
const hasCordova = type.indexOf('cordova') >= 0;
let cordovaOutput = '';
if (hasCordova) {
cordovaOutput = `'./${cordova.folder}/www'`;
}
const frameworkPlugin = {
core: [`import framework7 from 'rollup-plugin-framework7';`, 'framework7({ emitCss: false }),'],
react: [`import react from '@vitejs/plugin-react';`, 'react(),'],
vue: [
`import vue from '@vitejs/plugin-vue';`,
`vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.includes('swiper-') } } }),,`,
],
svelte: [``, 'svelte({preprocess: vitePreprocess()}),'],
};
// prettier-ignore
return indent(0, `
import path from 'path';
${frameworkPlugin[framework][0]}
${templateIf(hasCordova, () => `
import { createHtmlPlugin } from 'vite-plugin-html';
process.env.TARGET = process.env.TARGET || 'web';
const isCordova = process.env.TARGET === 'cordova';
`)}
const SRC_DIR = path.resolve(__dirname, './src');
const PUBLIC_DIR = path.resolve(__dirname, './public');
${templateIf(hasCordova, () => `
const BUILD_DIR = path.resolve(
__dirname,
isCordova ? ${cordovaOutput} : './www',
);
`, () => `
const BUILD_DIR = path.resolve(__dirname, './www',);
`)}
export default async () => {
${templateIf(framework === 'svelte', () => `
const { svelte, vitePreprocess } = await import('@sveltejs/vite-plugin-svelte');
`)}
return {
plugins: [
${frameworkPlugin[framework][1]}
${templateIf(hasCordova, () => `
createHtmlPlugin({
minify: false,
inject: {
data: {
TARGET: process.env.TARGET,
},
},
}),
`)}
],
root: SRC_DIR,
base: '',
publicDir: PUBLIC_DIR,
build: {
outDir: BUILD_DIR,
assetsInlineLimit: 0,
emptyOutDir: true,
rollupOptions: {
treeshake: false,
},
},
resolve: {
alias: {
'@': SRC_DIR,
},
},
server: {
host: true,
},
${templateIf(framework === 'core', () => `
esbuild: {
jsxFactory: '$jsx',
jsxFragment: '"Fragment"',
},
`)}
};
}
`);
};