Skip to content

Commit

Permalink
feat: uni-use and uni-promises clash
Browse files Browse the repository at this point in the history
  • Loading branch information
FliPPeDround committed Feb 1, 2024
1 parent 2100f73 commit a078f83
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 29 deletions.
File renamed without changes.
File renamed without changes.
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 @@ -5,5 +5,6 @@ export default function getData() {
importer: 'import uni from \'@dcloudio/vite-plugin-uni\'',
initializer: 'uni()',
}],
extraConfig: null,
}
}
2 changes: 1 addition & 1 deletion template/base/vite.config.js.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ export default defineConfig({
<%_ } _%>
],
<%_ if (extraConfig) { _%>
<%- extraConfig _%>,
<%- extraConfig.data _%>,
<%_ } _%>
})
12 changes: 7 additions & 5 deletions template/model/uniPromises/src/main.js.data.mjs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
export default function getData({ oldData }) {
const uniUsePlugin = {
id: 'uniUse',
const uniPromisesPlugin = {
id: 'uniPromises',
importer: `import 'core-js/actual/array/iterator';
import 'core-js/actual/promise';
import 'core-js/actual/object/assign';
import 'core-js/actual/promise/finally';`,
}
return {
...oldData,
plugins: oldData.plugins.flatMap(plugin =>
plugin.id === 'vue' ? [uniUsePlugin, plugin] : plugin,
),
plugins: oldData.plugins.some(item => item.id === 'uniUse')
? oldData.plugins
: oldData.plugins.flatMap(plugin =>
plugin.id === 'vue' ? [plugin, uniPromisesPlugin] : plugin,
),
}
}
18 changes: 8 additions & 10 deletions template/model/uniPromises/vite.config.js.data.mjs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
export default function getData({ oldData }) {
const promisesextraConfig = {
id: 'uniPromises',
extraConfig: `build: {
target: 'es6',
cssTarget: 'chrome61', // https://cn.vitejs.dev/config/build-options.html#build-csstarget
},
optimizeDeps: {
exclude: ['vue-demi'],
}`,
data: `build: {
target: 'es6',
cssTarget: 'chrome61', // https://cn.vitejs.dev/config/build-options.html#build-csstarget
},
optimizeDeps: {
exclude: ['vue-demi'],
}`,
}
return {
...oldData,
extraConfig: oldData.extraConfig.flatMap(config =>
config.id === 'uniUse' ? [...config, ...promisesextraConfig] : config,
),
extraConfig: oldData?.extraConfig?.id === 'uniUse' ? oldData.extraConfig : promisesextraConfig,
}
}
8 changes: 5 additions & 3 deletions template/model/uniUse/src/main.js.data.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import 'core-js/actual/promise/finally';`,
}
return {
...oldData,
plugins: oldData.plugins.flatMap(plugin =>
plugin.id === 'vue' ? [uniUsePlugin, plugin] : plugin,
),
plugins: oldData.plugins.some(item => item.id === 'uniPromises')
? oldData.plugins
: oldData.plugins.flatMap(plugin =>
plugin.id === 'vue' ? [plugin, uniUsePlugin] : plugin,
),
}
}
18 changes: 8 additions & 10 deletions template/model/uniUse/vite.config.js.data.mjs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
export default function getData({ oldData }) {
const uniUseextraConfig = {
id: 'uniUse',
extraConfig: `build: {
target: 'es6',
cssTarget: 'chrome61', // https://cn.vitejs.dev/config/build-options.html#build-csstarget
},
optimizeDeps: {
exclude: ['vue-demi'],
}`,
data: `build: {
target: 'es6',
cssTarget: 'chrome61', // https://cn.vitejs.dev/config/build-options.html#build-csstarget
},
optimizeDeps: {
exclude: ['vue-demi'],
}`,
}
return {
...oldData,
extraConfig: oldData.extraConfig.flatMap(config =>
config.id === 'uniPromises' ? [...config, ...uniUseextraConfig] : config,
),
extraConfig: uniUseextraConfig,
}
}

0 comments on commit a078f83

Please sign in to comment.