-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.mjs
61 lines (57 loc) · 1.92 KB
/
rollup.config.mjs
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
// @ts-check
import { createRequire } from 'node:module';
import json from '@rollup/plugin-json';
import replace from '@rollup/plugin-replace';
import run from '@rollup/plugin-run';
import { defineConfig } from 'rollup';
import esbuild from 'rollup-plugin-esbuild';
import externals from 'rollup-plugin-node-externals';
import { typescriptPaths } from 'rollup-plugin-typescript-paths';
const require = createRequire(import.meta.url);
const pkg = require('./package.json');
const preferConst = true; // Use "const" instead of "var"
const usePreserveModules = true; // `true` -> keep modules structure, `false` -> combine everything into a single file
const usePreserveModulesProduction = true; // `true` -> keep modules structure, `false` -> combine everything into a single file
const isProduction = process.env.NODE_ENV === 'production';
const isWatched = process.env.ROLLUP_WATCH === 'true'; // `true` if -w option is used
const useSourceMaps = process.env.NODE_ENV === 'debug';
export default defineConfig({
input: 'src/index.ts',
output: {
dir: 'dist',
format: 'es',
generatedCode: {
constBindings: preferConst,
},
preserveModules: isProduction
? usePreserveModulesProduction
: usePreserveModules,
preserveModulesRoot: 'src',
strict: true,
entryFileNames: '[name].mjs',
sourcemap: useSourceMaps,
},
treeshake: 'smallest',
plugins: [
externals(),
json({
preferConst: preferConst,
}),
replace({
'process.env.PKG_NAME': `"${pkg.name}"`,
'process.env.PKG_VERSION': `"${pkg.version}"`,
'process.env.PKG_DESCRIPTION': `"${pkg.description}"`,
'process.env.BUILD_NODE_ENV': `"${process.env.NODE_ENV}"`,
preventAssignment: true,
sourceMap: useSourceMaps,
}),
typescriptPaths({
preserveExtensions: true,
}),
esbuild({
legalComments: 'none',
target: 'esnext',
}),
isWatched ? run() : undefined,
],
});