generated from christian-bromann/typescript-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.mjs
132 lines (124 loc) · 3.48 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
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
import fs from 'node:fs'
import url from 'node:url'
import path from 'node:path'
import resolve from '@rollup/plugin-node-resolve'
import typescript from '@rollup/plugin-typescript'
import commonjs from '@rollup/plugin-commonjs'
import terser from '@rollup/plugin-terser'
import json from '@rollup/plugin-json'
import alias from '@rollup/plugin-alias'
import cleanup from 'rollup-plugin-cleanup'
const extensions = ['.js', '.ts']
const compilerOptions = { declaration: true, declarationMap: true }
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
const createPackageJSON = (dir = 'esm', type = 'module') => ({
name: 'create-package-json',
writeBundle: () => fs.promises.writeFile(
path.join(__dirname, 'build', dir, 'package.json'),
JSON.stringify({ type }, null, 4),
'utf-8'
)
})
const dynamicImportAlias = {
entries: {
'@azure/functions-core': './src/mocks.ts',
'applicationinsights-native-metrics': './src/mocks.ts'
}
}
/** @type {import('rollup').RollupOptions} */
const webview = {
input: 'src/webview/index.ts',
output: {
file: './build/webview.js',
format: 'esm',
sourcemap: true,
},
external: ['vscode'],
plugins: [
typescript({
outputToFilesystem: true,
tsconfig: './tsconfig.json',
declarationDir: 'build',
compilerOptions
}),
resolve({ extensions, browser: true }),
]
}
/** @type {import('rollup').RollupOptions} */
const esm = {
input: 'src/index.ts',
output: {
format: 'esm',
dir: 'build/esm',
exports: 'auto',
...(process.env.NODE_ENV === 'production'
? { plugins: [terser()] }
: {}
)
},
plugins: [
resolve({ extensions }),
json(),
alias(dynamicImportAlias),
commonjs({ defaultIsModuleExports: false }),
typescript({
outputToFilesystem: true,
tsconfig: './tsconfig.json',
outDir: 'build/esm',
declarationDir: 'build/esm',
compilerOptions
}),
createPackageJSON(),
cleanup({ comments: 'none' }),
],
external: ['vscode']
}
/** @type {import('rollup').RollupOptions} */
const cjs = {
...esm,
output: {
...esm.output,
format: 'cjs',
dir: 'build/cjs'
},
plugins: [
resolve({ extensions }),
json(),
alias(dynamicImportAlias),
commonjs({ defaultIsModuleExports: false }),
typescript({
outputToFilesystem: true,
tsconfig: './tsconfig.json',
outDir: 'build/cjs',
declarationDir: 'build/cjs',
compilerOptions
}),
createPackageJSON('cjs', 'commonjs'),
cleanup({ comments: 'none' })
],
external: ['vscode']
}
/** @type {import('rollup').RollupOptions} */
const browser = {
input: 'src/index.ts',
output: {
...esm.output,
dir: 'build/browser'
},
plugins: [
resolve({ extensions, browser: true }),
json(),
commonjs({ defaultIsModuleExports: false }),
typescript({
outputToFilesystem: true,
tsconfig: './tsconfig.json',
outDir: 'build/browser',
declarationDir: 'build/browser',
compilerOptions
}),
createPackageJSON(),
cleanup({ comments: 'none' }),
],
external: ['vscode']
}
export default [webview, esm, browser, cjs]