/
config.js
90 lines (80 loc) · 2.2 KB
/
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
const path = require('path');
const typescript = require('rollup-plugin-typescript2');
const replace = require('@rollup/plugin-replace');
const resolve = require('rollup-plugin-node-resolve');
const commonjs = require('rollup-plugin-commonjs');
const formatNameMap = {
'vee-validate': 'VeeValidate',
rules: 'VeeValidateRules',
i18n: 'VeeValidateI18n',
zod: 'VeeValidateZod',
};
const pkgNameMap = {
'vee-validate': 'vee-validate',
rules: 'vee-validate-rules',
i18n: 'vee-validate-i18n',
zod: 'vee-validate-zod',
};
const formatMap = {
es: 'esm',
umd: '',
};
function createConfig(pkg, format) {
const tsPlugin = typescript({
tsconfig: path.resolve(__dirname, '../tsconfig.json'),
cacheRoot: path.resolve(__dirname, '../node_modules/.rts2_cache'),
useTsconfigDeclarationDir: true,
tsconfigOverride: {
exclude: ['**/tests'],
},
});
const version = require(path.resolve(__dirname, `../packages/${pkg}/package.json`)).version;
const isEsm = format === 'es';
const config = {
input: {
input: path.resolve(__dirname, `../packages/${pkg}/src/index.ts`),
external: ['vue', isEsm ? '@vue/devtools-api' : undefined].filter(Boolean),
plugins: [
replace({
preventAssignment: true,
values: {
__VERSION__: version,
__DEV__: isEsm ? `(process.env.NODE_ENV !== 'production')` : 'false',
},
}),
tsPlugin,
resolve({
dedupe: ['fast-deep-equal/es6', 'fast-deep-equal', 'klona', 'klona/full'],
}),
commonjs(),
],
},
output: {
banner: `/**
* vee-validate v${version}
* (c) ${new Date().getFullYear()} Abdelrahman Awad
* @license MIT
*/`,
format,
name: format === 'umd' ? formatNameMap[pkg] : undefined,
globals: {
vue: 'Vue',
},
},
};
config.bundleName = `${pkgNameMap[pkg]}${formatMap[format] ? '.' + formatMap[format] : ''}.js`;
// if (options.env) {
// config.input.plugins.unshift(
// replace({
// 'process.env.NODE_ENV': JSON.stringify(options.env)
// })
// );
// }
return config;
}
module.exports = {
formatNameMap,
pkgNameMap,
formatMap,
createConfig,
};