-
Notifications
You must be signed in to change notification settings - Fork 72
/
vite.config.js
127 lines (126 loc) · 3.58 KB
/
vite.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import { resolve } from 'path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import eslintPlugin from 'vite-plugin-eslint'
import svgLoader from 'vite-svg-loader'
const isProduction = process.env.NODE_ENV === 'production'
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*/
}
}
}
export default defineConfig({
test: {
environment: 'jsdom',
threads: false,
clearMocks: true,
setupFiles: ['./vitest.setup.js'],
transformMode: {
web: [/\.[jt]sx$/],
}
},
base: './',
// define: { 'process.env.NODE_ENV': process.env.NODE_ENV },
build: {
lib: {
entry: resolve(__dirname, 'packages/formEditor/index.js'),
name: 'Everright-formEditor',
formats: ['es', 'umd'],
fileName: 'Everright-formEditor'
},
rollupOptions: {
external: ['vue', 'element-plus', 'vant'],
// https://rollupjs.org/guide/en/#big-list-of-options
output: {
globals: {
vue: 'Vue',
vant: 'Vant',
'element-plus': 'elementPlus'
}
}
}
},
resolve: {
alias: [
{
find: 'vuedraggable',
replacement: isProduction ? 'vuedraggable/src/vuedraggable' : 'vuedraggable'
},
{
find: '@ER',
replacement: resolve(__dirname, 'packages')
},
{
find: '@ER-examples',
replacement: resolve(__dirname, 'examples')
},
{
find: '@ER-test',
replacement: resolve(__dirname, 'test')
}
]
},
plugins: [
examplePlugin(),
svgLoader(),
vue(),
eslintPlugin(),
vueJsx({
})
],
css: {
preprocessorOptions: {
scss: {
additionalData: `
@use 'sass:math';
@use 'sass:map';
@use '@ER/theme/base.scss' as *;
`
}
}
}
})