Skip to content

Commit debc408

Browse files
committed
build: use rollup to inject plugin version into ESM export
1 parent df796b7 commit debc408

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"license": "MIT",
5050
"scripts": {
5151
"clean": "rimraf dist",
52-
"build": "npm run clean && npm run build:esm && npm run build:bundles",
52+
"build": "npm run clean && npm run build:esm && npm run build:bundles && rm -rf dist/esm-raw",
5353
"build:esm": "tsc",
5454
"build:bundles": "NODE_ENV=production rollup -c",
5555
"postbuild": "npm run check && npm run test:demo-projects",

rollup.config.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { babel } from '@rollup/plugin-babel'
1616
const __dirname = dirname(fileURLToPath(import.meta.url))
1717

1818
const baseConfig = {
19-
input: 'dist/esm/index.js',
19+
input: 'dist/esm-raw/index.js',
2020
output: {
2121
file: 'dist/contentful.cjs',
2222
format: 'cjs',
@@ -39,6 +39,22 @@ const baseConfig = {
3939
],
4040
}
4141

42+
const esmConfig = {
43+
input: 'dist/esm-raw/index.js',
44+
output: {
45+
dir: 'dist/esm', // Output directory
46+
format: 'esm', // Output module format
47+
preserveModules: true, // Preserve module structure
48+
},
49+
plugins: [
50+
replace({
51+
preventAssignment: true,
52+
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
53+
__VERSION__: JSON.stringify(pkg.version),
54+
}),
55+
],
56+
}
57+
4258
const cjsConfig = {
4359
...baseConfig,
4460
output: {
@@ -162,4 +178,4 @@ const browserMinConfig = {
162178
],
163179
}
164180

165-
export default [cjsConfig, browserConfig, browserMinConfig]
181+
export default [esmConfig, cjsConfig, browserConfig, browserMinConfig]

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"outDir": "./dist/esm",
3+
"outDir": "./dist/esm-raw",
44
"rootDir": "./lib",
55
"lib": ["dom", "esnext"],
66
"target": "ES2017",

0 commit comments

Comments
 (0)