-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.mjs
112 lines (104 loc) · 2.58 KB
/
rollup.config.mjs
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
import babel from '@rollup/plugin-babel'
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import typescript from 'rollup-plugin-typescript2'
import vue from 'rollup-plugin-vue'
import alias from '@rollup/plugin-alias'
import json from '@rollup/plugin-json'
import minimist from 'minimist'
import postcss from 'rollup-plugin-postcss'
import filesize from 'rollup-plugin-filesize'
import { importAssertionsPlugin } from 'rollup-plugin-import-assert'
import { DEFAULT_EXTENSIONS } from '@babel/core'
import tsConfig from './tsconfig.types.json' assert { type: "json" }
import pkg from './package.json' assert { type: "json" }
const PREFIX = '@eyes22798'
const name = pkg.name.split(PREFIX + '/')[1]
const kebabToCamel = (name) => {
name = name.replace(/-(\w)/g, (match, p1) => {
return p1.toUpperCase();
});
name = name.replace(/^\w/, (match) => {
return match.toUpperCase();
});
return name
}
const extensions = [...DEFAULT_EXTENSIONS, '.ts', '.tsx']
const argv = minimist(process.argv.slice(2))
const external = [
'vue',
'element-ui',
'@vue/composition-api'
]
const tsIncludes = ['*.ts', '*.tsx', '*.vue', '**/*.ts', '**/*.tsx', '**/*.vue']
const tsExcludes = ['tests/*', 'example/*']
const baseConfig = {
plugins: {
preVue: [
alias({
customResolver: resolve({
extensions: ['.js', '.jsx', '.vue']
})
})
],
vue: {
target: 'browser',
needMap: false
},
babel: {
exclude: 'node_modules/**',
extensions,
babelHelpers: 'bundled'
}
}
}
const buildConfig = {
input: './src/index.js',
external,
output: {
name: kebabToCamel(name),
format: 'esm',
file: `dist/index.esm.js`
},
plugins: [
...baseConfig.plugins.preVue,
vue(baseConfig.plugins.vue),
json(),
importAssertionsPlugin,
postcss(),
typescript({
tsconfigOverride: {
...tsConfig,
'include': tsIncludes,
'exclude': tsExcludes
},
abortOnError: false
}),
babel({
...baseConfig.plugins.babel,
presets: [
[
'@vue/cli-plugin-babel/preset',
{
useBuiltIns: false
}
],
'@babel/typescript'
]
}),
resolve({}),
commonjs({
include: 'node_modules/**'
}),
filesize()
]
}
if (argv.format === 'umd') {
buildConfig.output.format = 'umd'
buildConfig.output.file = `dist/index.umd.js`
}
if (argv.format === 'cjs') {
buildConfig.output.format = 'cjs'
buildConfig.output.file = `dist/index.common.js`
}
export default buildConfig