Skip to content

Commit 201f7d6

Browse files
build(rollup): fix rollup environment variables
1 parent 342befa commit 201f7d6

2 files changed

Lines changed: 19 additions & 14 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"build": "run-s build:*",
3131
"build:cjs": "tsc",
3232
"build:esm": "rollup --config --failAfterWarnings --environment ESM:true",
33-
"build:umd": "rollup --config --failAfterWarnings",
33+
"build:umd": "rollup --config --failAfterWarnings --environment UMD:true",
3434
"clean": "rm -rf .nyc_output coverage dist lib esm",
3535
"lint": "eslint .",
3636
"lint:fix": "npm run lint -- --fix",

rollup.config.mjs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
import { createRequire } from 'node:module';
2+
13
import alias from '@rollup/plugin-alias';
24
import commonjs from '@rollup/plugin-commonjs';
35
import resolve from '@rollup/plugin-node-resolve';
46
import terser from '@rollup/plugin-terser';
57
import typescript from '@rollup/plugin-typescript';
6-
import { createRequire } from 'module';
8+
79
const require = createRequire(import.meta.url);
810

9-
const getPlugins = (browser = false, minify = false, outDir) =>
11+
const getPlugins = ({ browser = false, minify = false, outDir }) =>
1012
[
1113
browser &&
1214
alias({
@@ -40,7 +42,7 @@ const getUMDConfig = (minify = false) => {
4042
name: 'HTMLDOMParser',
4143
sourcemap: true,
4244
},
43-
plugins: getPlugins(true, minify, 'dist'),
45+
plugins: getPlugins({ browser: true, minify, outDir: 'dist' }),
4446
};
4547
};
4648

@@ -52,7 +54,7 @@ const esmConfigs = [
5254
format: 'es',
5355
sourcemap: true,
5456
},
55-
plugins: getPlugins(false, false, 'esm'),
57+
plugins: getPlugins({ browser: false, minify: false, outDir: 'esm' }),
5658
},
5759
// Client build: use preserveModules for proper module structure
5860
{
@@ -65,7 +67,7 @@ const esmConfigs = [
6567
preserveModulesRoot: 'src/client',
6668
sourcemap: true,
6769
},
68-
plugins: getPlugins(true, false, 'esm/client'),
70+
plugins: getPlugins({ browser: true, minify: false, outDir: 'esm/client' }),
6971
},
7072
{
7173
input: 'src/server/html-to-dom.ts',
@@ -74,15 +76,18 @@ const esmConfigs = [
7476
format: 'es',
7577
sourcemap: true,
7678
},
77-
plugins: getPlugins(false, false, 'esm'),
79+
plugins: getPlugins({ browser: false, minify: false, outDir: 'esm' }),
7880
},
7981
];
8082

81-
const configs = [
82-
getUMDConfig(),
83-
getUMDConfig(true),
84-
...esmConfigs,
85-
{
83+
const configs = [];
84+
85+
if (process.env.ESM === 'true') {
86+
configs.push(...esmConfigs);
87+
}
88+
89+
if (process.env.UMD === 'true') {
90+
configs.push(getUMDConfig(), getUMDConfig(true), {
8691
input: require.resolve('htmlparser2'),
8792
output: {
8893
file: 'dist/htmlparser2.js',
@@ -91,7 +96,7 @@ const configs = [
9196
sourcemap: true,
9297
},
9398
plugins: [commonjs(), resolve({ browser: true })],
94-
},
95-
];
99+
});
100+
}
96101

97102
export default configs;

0 commit comments

Comments
 (0)