-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrollup.config.js
122 lines (110 loc) · 3.6 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
// @ts-nocheck
import * as path from 'path';
import { glob } from 'glob';
import typescript from '@rollup/plugin-typescript';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import { getSortedPackages } from './tasks/sorted-packages.js';
import {
genBaseBundleConfig,
configFromImportMaps,
directories,
clean,
importAndOptimizeMetaAssets,
} from './tasks/rollup-base-config.js';
/**
* @typedef {import("rollup").RollupOptions} RollupOptions
* @typedef {import("yargs-parser").Arguments} CommandLineArgs
*/
/**
* @param {CommandLineArgs} commandLineArgs
*
* @return {Promise<RollupOptions[]>}
*/
async function main(commandLineArgs) {
// add config specific command line options
const {
configScope = '@blindnet/*',
configIgnore,
configRaw,
configKeep,
configHelp,
} = commandLineArgs;
if (configHelp) {
// eslint-disable-next-line no-console
console.log(`Rollup: Specific config options
--configHelp Print this help message. [boolean]
--configScope (Lerna) Include only packages with names matching the given glob ("@blindnet/*" by default) [string]
--configIgnore (Lerna) Exclude packages with names matching the given glob. [string]
--configRaw Only run raw (no-bundling) build. [boolean]
--configKeep Skip output directory cleaning before build. [boolean]
`);
process.exit(0);
}
const packages = await getSortedPackages(configScope, configIgnore);
return packages.flatMap(pkg => {
/**
* Absolute path to package directory
*/
const basePath = path.relative(__dirname, pkg.location);
const { external, paths } = configFromImportMaps({ basePath });
const baseBundleConfig = genBaseBundleConfig(basePath);
const rawInputs = glob.sync('**/*.ts', {
cwd: path.join(basePath, directories.source),
absolute: true,
});
return [
// raw (no-bundling) esm build and typings for npm
{
input: rawInputs,
external,
output: [
{
dir: path.join(basePath, directories.output),
format: 'esm',
sourcemap: true,
assetFileNames: 'assets/[name].[ext]',
preserveModules: true,
preserveModulesRoot: path.join(basePath, directories.source),
},
],
plugins: [
...(configKeep ? [] : [clean(basePath)]),
importAndOptimizeMetaAssets(),
typescript({
compilerOptions: {
declaration: true,
declarationDir: path.join(basePath, directories.output),
rootDir: path.join(basePath, directories.source),
},
}),
],
},
...(configRaw
? []
: [
// bundle with all dependencies
// Warning: heavy file, only use when using a single component in a simple HTML page
{
...baseBundleConfig,
output: [
{
// @ts-ignore
...baseBundleConfig.output[0],
file: path.join(
basePath,
directories.output,
'index.all.min.js'
),
},
],
plugins: [
nodeResolve(),
// @ts-ignore
...baseBundleConfig.plugins,
],
},
]),
];
});
}
export default main;