-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.js
105 lines (94 loc) · 2.91 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
/*
* Copyright (c) 2023, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
/* eslint-env node */
const { readFileSync } = require('node:fs')
const path = require('node:path')
const replace = require('@rollup/plugin-replace')
const typescript = require('@rollup/plugin-typescript')
const { nodeResolve } = require('@rollup/plugin-node-resolve')
// The assumption is that the build script for each sub-package runs in that sub-package's directory
const packageRoot = process.cwd()
const packageJson = JSON.parse(
readFileSync(path.resolve(packageRoot, './package.json'), 'utf-8')
)
const {
name: packageName,
version,
dependencies,
peerDependencies,
} = packageJson
const banner = `/**\n * Copyright (C) 2023 salesforce.com, inc.\n */`
const footer = `/** version: ${version} */`
const { ROLLUP_WATCH: watchMode } = process.env
const formats = ['es', 'cjs']
const onwarn = ({ code, message }) => {
if (!process.env.ROLLUP_WATCH && code !== 'CIRCULAR_DEPENDENCY') {
throw new Error(message)
}
}
// These plugins are used both by the main Rollup build.
function sharedPlugins() {
const engineBrowserConfig = [
'@lwc/engine-server',
'@lwc/engine-dom',
].includes(packageName) && {
// This is only used inside @lwc/engine-dom and @lwc/engine-server
// Elsewhere, it _not_ be replaced, so that it can be replaced later (e.g. in @lwc/engine-core)
'process.env.IS_BROWSER':
packageName === '@lwc/engine-dom' ? 'true' : 'false',
}
return [
typescript({
target: 'es2017',
tsconfig: path.join(packageRoot, 'tsconfig.json'),
noEmitOnError: !watchMode, // in watch mode, do not exit with an error if typechecking fails
...(watchMode && {
incremental: true,
outputToFilesystem: true,
}),
}),
replace({
values: {
...engineBrowserConfig,
'process.env.LWC_VERSION': JSON.stringify(version),
},
preventAssignment: true,
}),
]
}
module.exports = {
input: path.resolve(packageRoot, './src/index.ts'),
output: formats.map((format) => ({
file: `dist/index${format === 'cjs' ? '.cjs' : ''}.js`,
sourcemap: true,
format,
banner,
footer,
exports: 'named',
esModule: true,
})),
plugins: [
nodeResolve({
// These are the devDeps that may be inlined into the dist/ bundles
// These include packages owned by us (LWC, observable-membrane), as well as parse5
// and its single dependency, which are bundled because it makes it simpler to distribute
resolveOnly: [
/^@lwc\//,
'observable-membrane',
/^parse5($|\/)/,
'entities',
/^@parse5\/tools/,
],
}),
...sharedPlugins(),
],
onwarn,
external: [
...Object.keys(dependencies || {}),
...Object.keys(peerDependencies || {}),
],
}