diff --git a/template/base/vite.config.js.data.mjs b/template/base/vite.config.js.data.mjs index 5934083..48c597e 100644 --- a/template/base/vite.config.js.data.mjs +++ b/template/base/vite.config.js.data.mjs @@ -6,5 +6,6 @@ export default function getData() { initializer: 'uni()', }], extraConfig: null, + dynamic: false, } } diff --git a/template/base/vite.config.js.ejs b/template/base/vite.config.js.ejs index 948c453..a40005b 100644 --- a/template/base/vite.config.js.ejs +++ b/template/base/vite.config.js.ejs @@ -2,9 +2,41 @@ import { fileURLToPath, URL } from 'node:url' import { defineConfig } from 'vite' <%_ for (const { importer } of plugins) { _%> -<%- importer %> +<%_ if (importer) { _%> +<%- importer _%> <%_ } _%> +<%_ } _%> + + +<%_ if (dynamic) { _%> +export default async () => { + <%_ for (const { dynamicImporter } of plugins) { _%> + <%_ if (dynamicImporter) { _%> + <%- dynamicImporter _%> + <%_ } _%> + <%_ } _%> + + return defineConfig({ + resolve: { + alias: { + '@': fileURLToPath(new URL('./src', import.meta.url)) + } + }, + plugins: [ + <%_ for (const { initializer } of plugins) { _%> + <%_ if (initializer) { _%> + <%- initializer _%>, + <%_ } _%> + <%_ } _%> + ], + <%_ if (extraConfig) { _%> + <%- extraConfig.data _%>, + <%_ } _%> + }) +} + +<%_ } else { _%> export default defineConfig({ resolve: { alias: { @@ -22,3 +54,6 @@ export default defineConfig({ <%- extraConfig.data _%>, <%_ } _%> }) +<%_ } _%> + + diff --git a/template/module/unocss/package.json b/template/module/unocss/package.json index d729dbf..9e85f72 100644 --- a/template/module/unocss/package.json +++ b/template/module/unocss/package.json @@ -2,6 +2,6 @@ "devDependencies": { "@iconify-json/carbon": "^1.1.31", "@uni-helper/unocss-preset-uni": "^0.2.8", - "unocss": "0.58.9" + "unocss": "^0.59.3" } } diff --git a/template/module/unocss/vite.config.js.data.mjs b/template/module/unocss/vite.config.js.data.mjs index 466957f..3e741e1 100644 --- a/template/module/unocss/vite.config.js.data.mjs +++ b/template/module/unocss/vite.config.js.data.mjs @@ -1,7 +1,7 @@ export default function getData({ oldData }) { const UnoCSSPlugin = { id: 'UnoCSS', - importer: 'import UnoCSS from \'unocss/vite\'', + dynamicImporter: `const UnoCSS = (await import('unocss/vite')).default`, initializer: 'UnoCSS()', } @@ -10,5 +10,6 @@ export default function getData({ oldData }) { plugins: oldData.plugins.flatMap(plugin => plugin.id === 'uni' ? [plugin, UnoCSSPlugin] : plugin, ), + dynamic: true, } }