-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
144 lines (131 loc) · 3.43 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// @ts-check
import commonJS from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import path from "node:path";
import process from "node:process";
import esbuild from "rollup-plugin-esbuild";
import polyfillNode from "rollup-plugin-polyfill-node";
import { __dirname, pkgsPath, require } from "./scripts/paths.js";
/**
* @type {string|undefined}
*/
const target = process.env.TARGET
if(!target){
throw new Error('TARGET package must be specified via --environment flag.')
}
const packageDir = path.resolve(pkgsPath,target);
const masterVersion = require('./package.json').version
/**
*
* @param {string} p
* @returns
*/
const resolve = (p) => path.resolve(packageDir, p);
const name = path.basename(packageDir)
/**
* @type {Record<string,import('rollup').OutputOptions>}
*/
const outputConfigs = {
"esm-bundler": {
file: resolve(`dist/${name}.esm-bundler.js`),
format: `es`,
},
"esm-browser": {
file: resolve(`dist/${name}.esm-browser.js`),
format: `es`,
},
cjs: {
file: resolve(`dist/${name}.cjs.js`),
format: `cjs`,
},
global: {
file: resolve(`dist/${name}.global.js`),
format: `iife`,
},
// runtime-only builds, for main "vue" package only
"esm-bundler-runtime": {
file: resolve(`dist/${name}.runtime.esm-bundler.js`),
format: `es`,
},
"esm-browser-runtime": {
file: resolve(`dist/${name}.runtime.esm-browser.js`),
format: "es",
},
"global-runtime": {
file: resolve(`dist/${name}.runtime.global.js`),
format: "iife",
},
};
/**
* @type {import('./scripts/types.d.ts').Manifest}
*/
const pkg = require(resolve(`package.json`));
const packageOptions = pkg.buildOptions || {};
const defaultFormats = ["esm-bundler", "cjs"];
const packageFormats = packageOptions.formats || defaultFormats;
const packageConfigs = packageFormats.map((format) =>
createConfig(format, outputConfigs[format])
);
export default packageConfigs;
/**
* @param {string} format
* @param {import('rollup').OutputOptions} output
* @returns {import('rollup').RollupOptions}
*/
function createConfig(format, output) {
let entryFile = /runtime$/.test(format) ? `src/runtime.ts` : `src/index.ts`;
function resolveExternal() {
return [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
];
}
function resolveDefine() {
const replacements = {
__VERSION__: `"${masterVersion}"`,
};
return replacements;
}
function resolveNodePlugins() {
let cjsIgnores = [];
const nodePlugins =
format === "cjs" && Object.keys(pkg.devDependencies || {}).length
? [
commonJS({
sourceMap: false,
ignore: cjsIgnores,
}),
...(format === "cjs" ? [] : [polyfillNode()]),
nodeResolve(),
]
: [];
return nodePlugins;
}
return {
input: resolve(entryFile),
external: resolveExternal(),
plugins: [
json({
namedExports: false,
}),
esbuild({
tsconfig: path.resolve(__dirname, "tsconfig.json"),
sourceMap: false,
minify: false,
target: "es2015",
define: resolveDefine(),
}),
...resolveNodePlugins(),
],
output,
onwarn: (msg, warn) => {
if (!/Circular/.test(msg.message)) {
warn(msg);
}
},
treeshake: {
moduleSideEffects: false,
},
};
}