From: Haoqun Jiang Date: Wed, 28 Jul 2021 09:38:56 +0000 (+0800) Subject: feat: make jsx support optional X-Git-Tag: v3.0.0-alpha.2~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=74fa619f2877a987b8c8f020e62ee07580de23d3;p=thirdparty%2Fvuejs%2Fcreate-vue.git feat: make jsx support optional --- diff --git a/index.js b/index.js index 6bca421c..7a39bdaa 100755 --- a/index.js +++ b/index.js @@ -102,7 +102,15 @@ async function init() { isValidPackageName(dir) || 'Invalid package.json name' }, { - name: 'shouldUseTypeScript', + name: 'shouldAddJSX', + type: () => (isValidTemplate ? null : 'toggle'), + message: 'Add JSX Support?', + initial: false, + active: 'Yes', + inactive: 'No' + }, + { + name: 'shouldAddTypeScript', type: () => (isValidTemplate ? null : 'toggle'), message: 'Add TypeScript?', initial: false, @@ -143,7 +151,8 @@ async function init() { const { packageName = toValidPackageName(defaultProjectName), shouldOverwrite, - shouldUseTypeScript = isValidTemplate && template.includes('-ts'), + shouldAddJSX, + shouldAddTypeScript = isValidTemplate && template.includes('-ts'), isSPA = isValidTemplate && template.includes('spa'), shouldAddCypress = isValidTemplate && template.includes('-with-tests') } = result @@ -171,10 +180,13 @@ async function init() { // Add configs. render('config/base') + if (shouldAddJSX) { + render('config/jsx') + } if (shouldAddCypress) { render('config/cypress') } - if (shouldUseTypeScript) { + if (shouldAddTypeScript) { render('config/typescript') // rename all `.js` files to `.ts` @@ -198,7 +210,7 @@ async function init() { // Render code template. // prettier-ignore const codeTemplate = - (shouldUseTypeScript ? 'typescript-' : '') + + (shouldAddTypeScript ? 'typescript-' : '') + (isSPA ? 'spa' : 'default') render(`code/${codeTemplate}`) diff --git a/template/config/base/package.json b/template/config/base/package.json index 525ad87b..a995a77e 100644 --- a/template/config/base/package.json +++ b/template/config/base/package.json @@ -10,7 +10,6 @@ }, "devDependencies": { "@vitejs/plugin-vue": "^1.2.5", - "@vitejs/plugin-vue-jsx": "^1.1.6", "@vue/compiler-sfc": "^3.1.5", "vite": "^2.4.3" } diff --git a/template/config/base/vite.config.js b/template/config/base/vite.config.js index 032e163c..24c2e504 100644 --- a/template/config/base/vite.config.js +++ b/template/config/base/vite.config.js @@ -1,10 +1,9 @@ import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' -import vueJsx from '@vitejs/plugin-vue-jsx' // https://vitejs.dev/config/ export default defineConfig({ - plugins: [vue(), vueJsx()], + plugins: [vue()], resolve: { alias: { '@/': new URL('./src/', import.meta.url).pathname diff --git a/template/config/jsx/package.json b/template/config/jsx/package.json new file mode 100644 index 00000000..f356488e --- /dev/null +++ b/template/config/jsx/package.json @@ -0,0 +1,5 @@ +{ + "devDependencies": { + "@vitejs/plugin-vue-jsx": "^1.1.6" + } +} diff --git a/template/config/jsx/vite.config.js b/template/config/jsx/vite.config.js new file mode 100644 index 00000000..032e163c --- /dev/null +++ b/template/config/jsx/vite.config.js @@ -0,0 +1,13 @@ +import { defineConfig } from 'vite' +import vue from '@vitejs/plugin-vue' +import vueJsx from '@vitejs/plugin-vue-jsx' + +// https://vitejs.dev/config/ +export default defineConfig({ + plugins: [vue(), vueJsx()], + resolve: { + alias: { + '@/': new URL('./src/', import.meta.url).pathname + } + } +})