Skip to content

Commit

Permalink
feat: support esm package
Browse files Browse the repository at this point in the history
  • Loading branch information
FliPPeDround committed Apr 17, 2024
1 parent 5eebd6e commit 4d1275a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
1 change: 1 addition & 0 deletions template/base/vite.config.js.data.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ export default function getData() {
initializer: 'uni()',
}],
extraConfig: null,
dynamic: false,
}
}
37 changes: 36 additions & 1 deletion template/base/vite.config.js.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -22,3 +54,6 @@ export default defineConfig({
<%- extraConfig.data _%>,
<%_ } _%>
})
<%_ } _%>
2 changes: 1 addition & 1 deletion template/module/unocss/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
3 changes: 2 additions & 1 deletion template/module/unocss/vite.config.js.data.mjs
Original file line number Diff line number Diff line change
@@ -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()',
}

Expand All @@ -10,5 +10,6 @@ export default function getData({ oldData }) {
plugins: oldData.plugins.flatMap(plugin =>
plugin.id === 'uni' ? [plugin, UnoCSSPlugin] : plugin,
),
dynamic: true,
}
}

0 comments on commit 4d1275a

Please sign in to comment.