-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollup.config.js
More file actions
87 lines (75 loc) · 2.27 KB
/
rollup.config.js
File metadata and controls
87 lines (75 loc) · 2.27 KB
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
import path from 'path';
import ts from 'rollup-plugin-typescript2';
import json from '@rollup/plugin-json';
const pkg = process.env.PACKAGE;
const packagesDir = path.resolve(__dirname, 'packages')
const packageDir = path.resolve(packagesDir, pkg)
const pkgJson = require(path.resolve(packageDir, 'package.json'))
const resolve = p => path.resolve(packageDir, p)
// ensure TS checks only once for each build
let hasTSChecked = false
const outputConfigs = {
cjs: {
file: path.resolve(__dirname, `packages/${pkg}/dist/${pkg}.cjs.js`),
format: `cjs`
}
}
const defaultFormats = ['cjs']
const packageConfigs = defaultFormats.map(format => createConfig(format, outputConfigs[format]))
export default packageConfigs
function createConfig(format, output, plugins = []) {
if (!output) {
console.log(require('chalk').yellow(`invalid format: "${format}"`))
process.exit(1)
}s
output.externalLiveBindings = false
const shouldEmitDeclarations = !hasTSChecked
const tsPlugin = ts({
check: !hasTSChecked,
tsconfig: path.resolve(__dirname, 'tsconfig.json'),
tsconfigOverride: {
compilerOptions: {
declaration: shouldEmitDeclarations,
},
exclude: ['**/__tests__']
}
})
// we only need to check TS and generate declarations once for each build.
// it also seems to run into weird issues when checking multiple times
// during a single build.
hasTSChecked = true
const entryFile = `index.ts`
// the browser builds of @vue/compiler-sfc requires postcss to be available
// as a global (e.g. http://wzrd.in/standalone/postcss)
const nodePlugins = [
require('@rollup/plugin-node-resolve').nodeResolve({
preferBuiltins: true
}),
require('@rollup/plugin-commonjs')({
sourceMap: false
})
]
return {
external: Object.keys(pkgJson.dependencies || {}),
input: resolve(entryFile),
// Global and Browser ESM builds inlines everything so that they can be
// used alone.
plugins: [
json({
namedExports: false
}),
tsPlugin,
...nodePlugins,
...plugins
],
output,
onwarn: (msg, warn) => {
if (!/Circular/.test(msg)) {
warn(msg)
}
},
treeshake: {
moduleSideEffects: false
}
}
}