-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
rollup.config.js
90 lines (81 loc) · 2.31 KB
/
rollup.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
// @ts-check
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import resolve from '@rollup/plugin-node-resolve'
import typescript from '@rollup/plugin-typescript'
import { generateRollupOptions } from '@vuedx/monorepo-tools'
import dts from 'rollup-plugin-dts'
import { define, processVueSFC } from './scripts/rollup-plugins'
const configs = ['packages/*', 'extensions/*'].flatMap((pattern) => {
return generateRollupOptions({
dirPatterns: [pattern],
extend({ rollupOptions: options, tsconfig, packageJson, packageRoot }) {
if (options.input.endsWith('.d.ts')) {
return {
...options,
plugins: [dts()],
}
}
if (tsconfig?.configFile == null) {
throw new Error(`${packageJson.name} does not have a tsconfig.json`)
}
const config = {
...options,
plugins: [
resolve(),
commonjs(),
typescript({
tsconfig: tsconfig?.configFile,
compilerOptions: {
declaration: true,
declarationMap: true,
declarationDir: 'types',
},
}),
...options.plugins,
json(),
define(packageJson.version ?? ''),
compiler(),
],
}
if (packageJson.name === '@vuedx/compiler-sfc') {
config.plugins.splice(1, 0, processVueSFC())
config.treeshake = {
moduleSideEffects: () => false,
}
config.onwarn = (warning, defaultHandler) => {
if (
warning.code === 'UNUSED_EXTERNAL_IMPORT' &&
warning.source === 'lru-cache'
)
return
defaultHandler(warning)
}
}
return config
},
})
})
// console.log(require('util').inspect(configs, false, 6))
export default configs
/**
*
* @returns {import('rollup').Plugin}
*/
function compiler() {
return {
name: 'vue/compiler',
generateBundle(options, bundle) {
Object.values(bundle).forEach((chunk) => {
if (chunk.type === 'chunk') {
if (chunk.code.includes('@vue/compiler-core')) {
chunk.code = chunk.code.replace(
/@vue\/compiler-core/g,
'@vue/compiler-core/dist/compiler-core.cjs.js',
)
}
}
})
},
}
}