diff --git a/packages/toolkits/pro/template/tinyvue/.env b/packages/toolkits/pro/template/tinyvue/.env index 9de4842e..27a9a3e9 100644 --- a/packages/toolkits/pro/template/tinyvue/.env +++ b/packages/toolkits/pro/template/tinyvue/.env @@ -1,5 +1,8 @@ VITE_CONTEXT=/vue-pro/ VITE_BASE_API=/api VITE_SERVER_HOST= http://127.0.0.1:3000 +VITE_MOCK_HOST= http://127.0.0.1:8848 VITE_USE_MOCK= false VITE_MOCK_IGNORE= /api/user/userInfo,/api/user/login,/api/user/register,/api/employee/getEmployee + +VITE_MOCK_SERVER_HOST=/mock diff --git a/packages/toolkits/pro/template/tinyvue/babel.config.js b/packages/toolkits/pro/template/tinyvue/babel.config.js index dd6f53ce..3f7f17c9 100644 --- a/packages/toolkits/pro/template/tinyvue/babel.config.js +++ b/packages/toolkits/pro/template/tinyvue/babel.config.js @@ -1,3 +1,5 @@ module.exports = { - plugins: ['@vue/babel-plugin-jsx'], + plugins: [ + '@vue/babel-plugin-jsx', + ] }; diff --git a/packages/toolkits/pro/template/tinyvue/config/vite.config.base.ts b/packages/toolkits/pro/template/tinyvue/config/vite.config.base.ts index f1dce32f..b44c6b6f 100644 --- a/packages/toolkits/pro/template/tinyvue/config/vite.config.base.ts +++ b/packages/toolkits/pro/template/tinyvue/config/vite.config.base.ts @@ -3,25 +3,12 @@ import { defineConfig } from 'vite'; import vue from '@vitejs/plugin-vue'; import vueJsx from '@vitejs/plugin-vue-jsx'; import svgLoader from 'vite-svg-loader'; -import { viteMockServe } from 'vite-plugin-mock'; - -const useMock = !! process.env.VITE_USE_MOCK const config = { plugins: [ vue(), vueJsx(), svgLoader({ svgoConfig: {} }), - viteMockServe({ - mockPath: '../src/mock', // mock文件地址 - localEnabled:useMock, // 开发打包开关 - prodEnabled:true, // 生产打包开关 // 这样可以控制关闭mock的时候不让mock打包到最终代码内 - injectCode: ` import { setupProdMockServer } from '../src/mockProdServer'; setupProdMockServer(); `, - logger: true, // 是否在控制台显示请求日志 - supportTs: false, // 打开后,可以读取 ts 文件模块。 请注意,打开后将无法监视.js 文件 - watchFiles:true, - injectFile: resolve('../src/main.ts'), - }) ], build: { outDir: resolve(__dirname, '../dist'), diff --git a/packages/toolkits/pro/template/tinyvue/config/vite.config.dev.ts b/packages/toolkits/pro/template/tinyvue/config/vite.config.dev.ts index b18cbd3a..f6b5f207 100644 --- a/packages/toolkits/pro/template/tinyvue/config/vite.config.dev.ts +++ b/packages/toolkits/pro/template/tinyvue/config/vite.config.dev.ts @@ -13,6 +13,11 @@ const proxyConfig = { '' ), }, + [loadEnv('', process.cwd()).VITE_MOCK_SERVER_HOST]: { + target: loadEnv('', process.cwd()).VITE_MOCK_HOST, + changeOrigin: true, + rewrite: (path:string) => path.replace(/^\/mock/, '') + } }; export default mergeConfig( { diff --git a/packages/toolkits/pro/template/tinyvue/config/vite.config.preview.base.ts b/packages/toolkits/pro/template/tinyvue/config/vite.config.preview.base.ts index b815ab17..018e9924 100644 --- a/packages/toolkits/pro/template/tinyvue/config/vite.config.preview.base.ts +++ b/packages/toolkits/pro/template/tinyvue/config/vite.config.preview.base.ts @@ -3,23 +3,12 @@ import { defineConfig } from 'vite'; import vue from '@vitejs/plugin-vue'; import vueJsx from '@vitejs/plugin-vue-jsx'; import svgLoader from 'vite-svg-loader'; -import { viteMockServe } from 'vite-plugin-mock'; export default defineConfig({ plugins: [ vue(), vueJsx(), svgLoader({ svgoConfig: {} }), - viteMockServe({ - // 更多配置见最下方 - mockPath: '../src/mock', // mock文件地址 - localEnabled: true, // 开发打包开关 - prodEnabled: true, // 生产打包开关 // 这样可以控制关闭mock的时候不让mock打包到最终代码内 - injectCode: ` import { setupProdMockServer } from '../src/mockProdServer'; setupProdMockServer(); `, - logger: false, // 是否在控制台显示请求日志 - supportTs: false, // 打开后,可以读取 ts 文件模块。 请注意,打开后将无法监视.js 文件 - injectFile: resolve('../src/main.ts'), - }), ], build: { outDir: resolve(__dirname, '../dist/vue-pro/pages'), diff --git a/packages/toolkits/pro/template/tinyvue/config/vite.config.prod.ts b/packages/toolkits/pro/template/tinyvue/config/vite.config.prod.ts index a5ddb3af..abccb66c 100644 --- a/packages/toolkits/pro/template/tinyvue/config/vite.config.prod.ts +++ b/packages/toolkits/pro/template/tinyvue/config/vite.config.prod.ts @@ -1,12 +1,11 @@ import { mergeConfig } from 'vite'; -import baseConig from './vite.config.base'; +import baseConfig from './vite.config.base'; import configCompressPlugin from './plugin/compress'; import configVisualizerPlugin from './plugin/visualizer'; export default mergeConfig( { mode: 'production', - mock: true, plugins: [configCompressPlugin('gzip'), configVisualizerPlugin()], build: { rollupOptions: { @@ -19,5 +18,5 @@ export default mergeConfig( chunkSizeWarningLimit: 2000, }, }, - baseConig + baseConfig ); diff --git a/packages/toolkits/pro/template/tinyvue/dev.env b/packages/toolkits/pro/template/tinyvue/dev.env new file mode 100644 index 00000000..27a9a3e9 --- /dev/null +++ b/packages/toolkits/pro/template/tinyvue/dev.env @@ -0,0 +1,8 @@ +VITE_CONTEXT=/vue-pro/ +VITE_BASE_API=/api +VITE_SERVER_HOST= http://127.0.0.1:3000 +VITE_MOCK_HOST= http://127.0.0.1:8848 +VITE_USE_MOCK= false +VITE_MOCK_IGNORE= /api/user/userInfo,/api/user/login,/api/user/register,/api/employee/getEmployee + +VITE_MOCK_SERVER_HOST=/mock diff --git a/packages/toolkits/pro/template/tinyvue/index.html b/packages/toolkits/pro/template/tinyvue/index.html index 0b1d5c7f..3066b49c 100644 --- a/packages/toolkits/pro/template/tinyvue/index.html +++ b/packages/toolkits/pro/template/tinyvue/index.html @@ -8,6 +8,6 @@
- +