1+ import { createRequire } from 'node:module' ;
2+
13import alias from '@rollup/plugin-alias' ;
24import commonjs from '@rollup/plugin-commonjs' ;
35import resolve from '@rollup/plugin-node-resolve' ;
46import terser from '@rollup/plugin-terser' ;
57import typescript from '@rollup/plugin-typescript' ;
6- import { createRequire } from 'module' ;
8+
79const 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
97102export default configs ;
0 commit comments