-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
79 lines (69 loc) · 1.94 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
import path from 'path';
import ts from 'rollup-plugin-typescript2';
import json from '@rollup/plugin-json';
const pkgJson = require('./package.json');
// ensure TS checks only once for each build
let hasTSChecked = false;
const outputConfigs = {
cjs: {
file: path.resolve(__dirname, `dist/utils.cjs.js`),
format: `cjs`
}
};
const defaultFormats = ['cjs'];
const packageFormats = defaultFormats;
const packageConfigs = packageFormats.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);
}
output.externalLiveBindings = false;
const shouldEmitDeclarations = !hasTSChecked;
const tsPlugin = ts({
check: !hasTSChecked,
tsconfig: path.resolve(__dirname, 'tsconfig.json'),
tsconfigOverride: {
compilerOptions: {
declaration: shouldEmitDeclarations,
},
exclude: ['**/__tests__', 'test-dts'],
},
});
// 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;
// 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: 'src/index.ts',
plugins: [
json({
namedExports: false
}),
tsPlugin,
...nodePlugins,
...plugins
],
output,
onwarn: (msg, warn) => {
if (!/Circular/.test(msg)) {
warn(msg)
}
},
treeshake: {
moduleSideEffects: false
}
}
}