|
@@ -10,6 +10,7 @@ import path from 'path'
|
|
|
import pkg from './package.json'
|
|
|
import dayjs from 'dayjs'
|
|
|
import { wrapperEnv } from './build/getEnv'
|
|
|
+const isProduction = process.env.NODE_ENV === 'production'
|
|
|
|
|
|
const { dependencies, devDependencies, name, version } = pkg
|
|
|
const __APP_INFO__ = {
|
|
@@ -17,6 +18,56 @@ const __APP_INFO__ = {
|
|
|
lastBuildTime: dayjs().format('YYYY-MM-DD HH:mm:ss')
|
|
|
}
|
|
|
|
|
|
+const examplePlugin = () => {
|
|
|
+ let config
|
|
|
+
|
|
|
+ return {
|
|
|
+ name: 'custom-vuedraggableAndSortable',
|
|
|
+ transform(code, id) {
|
|
|
+ /*eslint-disable*/
|
|
|
+ if (isProduction) {
|
|
|
+ if (/vuedraggable\.js/.test(id)) {
|
|
|
+ return code.replace('this._sortable = new Sortable(targetDomElement, sortableOptions);', (...e) => {
|
|
|
+ return `Sortable.mount($attrs.plugins || []);
|
|
|
+ ${e[0]}`
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if (/sortablejs/.test(id)) {
|
|
|
+ return code.replace(`plugins.forEach(function (p) {
|
|
|
+ if (p.pluginName === plugin.pluginName) {
|
|
|
+ throw "Sortable: Cannot mount plugin ".concat(plugin.pluginName, " more than once");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ plugins.push(plugin);`, (...e) => {
|
|
|
+ return `if (!plugins.filter(e => e.pluginName === plugin.pluginName).length) {
|
|
|
+ window.plugins = plugins;
|
|
|
+ plugins.push(plugin);}`
|
|
|
+ })
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (/vuedraggable/.test(id)) {
|
|
|
+ let result = code.replace('this._sortable = new external_commonjs_sortablejs_commonjs2_sortablejs_amd_sortablejs_root_Sortable_default.a(targetDomElement, sortableOptions);', (...e) => {
|
|
|
+ return `external_commonjs_sortablejs_commonjs2_sortablejs_amd_sortablejs_root_Sortable_default.a.mount($attrs.plugins || []);
|
|
|
+ ${e[0]}`
|
|
|
+ })
|
|
|
+ result = result.replace(`plugins.forEach(function(p) {
|
|
|
+ if (p.pluginName === plugin.pluginName) {
|
|
|
+ throw "Sortable: Cannot mount plugin ".concat(plugin.pluginName, " more than once");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ plugins.push(plugin);`, (...e) => {
|
|
|
+ return `if (!plugins.filter(e => e.pluginName === plugin.pluginName).length) {
|
|
|
+ window.plugins = plugins;
|
|
|
+ plugins.push(plugin);}`
|
|
|
+ })
|
|
|
+ return result
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /*eslint-disable*/
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
// https://vitejs.dev/config/
|
|
|
export default defineConfig(({ mode /*command,*/ }: ConfigEnv): UserConfig => {
|
|
|
// if (command === 'serve') {
|
|
@@ -40,7 +91,8 @@ export default defineConfig(({ mode /*command,*/ }: ConfigEnv): UserConfig => {
|
|
|
alias: {
|
|
|
'@': path.resolve(__dirname, './src'),
|
|
|
'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
|
|
|
- '@ER': path.resolve(__dirname, './src/components/packages')
|
|
|
+ '@ER': path.resolve(__dirname, './src/components/packages'),
|
|
|
+ vuedraggable: isProduction ? 'vuedraggable/src/vuedraggable' : 'vuedraggable'
|
|
|
},
|
|
|
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.vue', '.json'] // 默认 ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json']
|
|
|
},
|
|
@@ -88,7 +140,8 @@ export default defineConfig(({ mode /*command,*/ }: ConfigEnv): UserConfig => {
|
|
|
// 指定symbolId格式
|
|
|
symbolId: 'icon-[dir]-[name]'
|
|
|
}),
|
|
|
- svgLoader()
|
|
|
+ svgLoader(),
|
|
|
+ examplePlugin()
|
|
|
]
|
|
|
}
|
|
|
})
|