-
Notifications
You must be signed in to change notification settings - Fork 2
/
tsdx.config.js
51 lines (46 loc) · 1.63 KB
/
tsdx.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
// @ts-check
/**
* @typedef {Object} TsdxOptions
* @property {string} input - path to file
* @property {string} name - Safe name (for UMD)
* @property {'node' | 'browser'} target - JS target
* @property {'cjs' | 'umd' | 'esm'} format - Module format
* @property {'development' | 'production'} env - Environment
* @property { string} tsconfig - Path to tsconfig file
* @property { boolean} extractErrors - Is opt-in invariant error extraction active?
* @property { boolean} minify - Is minifying?
* @property { boolean} writeMeta - Is this the very first rollup config (and thus should one-off metadata be extracted)?
*/
const safePackageName = (name) =>
name.toLowerCase().replace(/((^[^a-zA-Z]+)|[^\w.-])|([^a-zA-Z0-9]+$)/g, '');
// Not transpiled with TypeScript or Babel, so use plain Es6/Node.js!
module.exports = {
// This function will run for each entry/format/env combination
/**
*
* @param {import("rollup").RollupOptions} config
* @param {TsdxOptions} options
*/
rollup(config, options) {
config.output = { dir: 'dist' };
delete config.output.file;
config.output.entryFileNames = `${safePackageName(options.name)}.[format]${
options.env
? `.${options.env}${options.env === 'production' ? '.min' : ''}`
: ''
}.js`;
const ssrConfig = {
...config,
input: 'src/ssr.tsx',
output: {
...config.output,
entryFileNames: `ssr.[format]${
options.env
? `.${options.env}${options.env === 'production' ? '.min' : ''}`
: ''
}.js`,
},
};
return [config, ssrConfig]; // always return a config.
},
};