]> git.ipfire.org Git - thirdparty/vuejs/create-vue.git/commitdiff
feat: make jsx support optional
authorHaoqun Jiang <haoqunjiang@gmail.com>
Wed, 28 Jul 2021 09:38:56 +0000 (17:38 +0800)
committerHaoqun Jiang <haoqunjiang@gmail.com>
Wed, 28 Jul 2021 09:38:56 +0000 (17:38 +0800)
index.js
template/config/base/package.json
template/config/base/vite.config.js
template/config/jsx/package.json [new file with mode: 0644]
template/config/jsx/vite.config.js [new file with mode: 0644]

index 6bca421c20531bfe76fbaaa181645b423f150090..7a39bdaad681fda576185e2c9e971e49bd410632 100755 (executable)
--- 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}`)
 
index 525ad87b7c0f6d54a63ba692f423ae2f70538881..a995a77eab8b1152cd548963cd1827dd7e86a93b 100644 (file)
@@ -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"
   }
index 032e163cf57f312792c106d417534e89491a0727..24c2e504741f170ece3d9b0eb26670c3d7c90ecd 100644 (file)
@@ -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 (file)
index 0000000..f356488
--- /dev/null
@@ -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 (file)
index 0000000..032e163
--- /dev/null
@@ -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
+    }
+  }
+})