Browse Source

fix: codesandbox (#1029)

* fix: 修复codesandbox

* fix: 修复codesandbox

* fix: 还原

* fix: 撤销input单元测试
ailululu 3 years ago
parent
commit
743806478b

+ 0 - 1
src/packages/__VUE/input/demo.vue

@@ -58,7 +58,6 @@ export default createDemo({
     const clear = (value: string | number) => {
       console.log('clear:', value);
     };
-
     return {
       state,
       change,

+ 33 - 4
src/sites/doc/components/demo-block/demoBlock.vue

@@ -32,6 +32,7 @@ import { compressText, copyCodeHtml, decompressText } from './basedUtil';
 
 import { getParameters } from 'codesandbox/lib/api/define';
 import codesandboxPackage from './demoCodePackage.json'; // 引入josn文件
+import codesandboxtsconfig from './demoCodetsconfig.json'; // 引入ts文件
 
 export default {
   setup(props, ctx) {
@@ -61,6 +62,28 @@ import NutUI from "@nutui/nutui";
 import "@nutui/nutui/dist/style.css";
 createApp(App).use(NutUI).mount("#app");`;
 
+    const codesandboxHtml = `<!DOCTYPE html> 
+<html lang="en">
+  <head>
+    <meta charset="UTF-8" />
+    <link rel="icon" href="/favicon.ico" />
+    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+    <title>Vite App</title>
+  </head>
+  <body>
+    <div id="app"></div>
+    <script type="module" src="/src/main.ts"><\/script>
+  </body>
+</html>`;
+
+    const codesandboxVite = `import { defineConfig } from 'vite'
+import vue from '@vitejs/plugin-vue'
+
+// https://vitejs.dev/config/
+export default defineConfig({
+  plugins: [vue()]
+});`;
+
     const onlineCode = ref(null);
     const sourceMainJs = compressText(sourceMainJsStr);
     const mainJs = ref(sourceMainJs);
@@ -71,17 +94,23 @@ createApp(App).use(NutUI).mount("#app");`;
     const jumpHref = ref(``);
     const jumpHref1 = ref(``);
     onMounted(() => {
-      console.log('codesandboxPackage', codesandboxPackage);
-      console.log('onlineCode', onlineCode.value.dataset);
       const sourceValue = decompressText(onlineCode.value.dataset.value);
-      console.log('sourceValue', sourceValue);
 
       const parameters = getParameters({
         files: {
           'package.json': {
             content: codesandboxPackage
           },
-          'src/main.js': {
+          'tsconfig.json': {
+            content: codesandboxtsconfig
+          },
+          'vite.config.ts': {
+            content: codesandboxVite
+          },
+          'index.html': {
+            content: codesandboxHtml
+          },
+          'src/main.ts': {
             content: MainJsStr
           },
           'src/App.vue': {

+ 13 - 40
src/sites/doc/components/demo-block/demoCodePackage.json

@@ -1,47 +1,20 @@
 {
-  "name": "nutui3-demo",
-  "version": "0.1.0",
+  "name": "nutui3-vite-demo",
   "private": true,
+  "version": "0.0.0",
   "scripts": {
-    "serve": "vue-cli-service serve",
-    "build": "vue-cli-service build",
-    "lint": "vue-cli-service lint"
+    "dev": "vite",
+    "build": "vue-tsc --noEmit && vite build",
+    "preview": "vite preview"
   },
   "dependencies": {
-    "@nutui/nutui": "3.1.16",
-    "@vue/babel-plugin-jsx": "1.1.1",
-    "core-js": "^3.6.5",
-    "typescript": "4.5.5",
-    "vue": "^3.0.0-0"
+    "@nutui/nutui": "^3.1.16",
+    "vue": "^3.2.25"
   },
   "devDependencies": {
-    "@vue/cli-plugin-babel": "~4.5.0",
-    "@vue/cli-plugin-eslint": "~4.5.0",
-    "@vue/cli-service": "~4.5.0",
-    "@vue/compiler-sfc": "^3.0.0-0",
-    "babel-eslint": "^10.1.0",
-    "eslint": "^6.7.2",
-    "eslint-plugin-vue": "^7.0.0-0"
-  },
-  "eslintConfig": {
-    "root": true,
-    "env": {
-      "node": true
-    },
-    "extends": [
-      "plugin:vue/vue3-essential",
-      "eslint:recommended"
-    ],
-    "parserOptions": {
-      "parser": "babel-eslint"
-    },
-    "rules": {}
-  },
-  "browserslist": [
-    "> 1%",
-    "last 2 versions",
-    "not dead"
-  ],
-  "keywords": [],
-  "description": ""
-}
+    "@vitejs/plugin-vue": "^2.2.0",
+    "typescript": "^4.5.4",
+    "vite": "^2.8.0",
+    "vue-tsc": "^0.29.8"
+  }
+}

+ 16 - 0
src/sites/doc/components/demo-block/demoCodetsconfig.json

@@ -0,0 +1,16 @@
+{
+  "compilerOptions": {
+    "target": "esnext",
+    "useDefineForClassFields": true,
+    "module": "esnext",
+    "moduleResolution": "node",
+    "strict": true,
+    "jsx": "preserve",
+    "sourceMap": true,
+    "resolveJsonModule": true,
+    "esModuleInterop": true,
+    "lib": ["esnext", "dom"]
+  },
+  "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
+  "references": [{ "path": "./tsconfig.node.json" }]
+}