Skip to content

Commit ac9818a

Browse files
committed
refactor(rollupconfig): remove umd support, add banner, and remove browserified modules
Remove the UMD support in favor of cjs for node env, esm for browser es6 modules, and iife as standalone browser version. Add _computeBanner private method to add package version under dev env. BREAKING CHANGE: Remove UMD support
1 parent 7e26840 commit ac9818a

2 files changed

Lines changed: 52 additions & 23 deletions

File tree

configs/rollup.conf.js

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,51 @@
66
* @description The file manage the rollup configuration for build the library using differents arguments. It allow to build with two type of environment (dev and prod), and differents output format.
77
* Use npm run help to display all available build options.
88
*
9-
* @requires {@link module: [rollup-plugin-node-builtins]{@link https://github.com/calvinmetcalf/rollup-plugin-node-builtins}}
109
* @requires {@link module: [rollup-plugin-commonjs]{@link https://github.com/rollup/rollup-plugin-commonjs}}
11-
* @requires {@link module: [rollup-plugin-json]{@link https://github.com/rollup/rollup-plugin-json}}
1210
* @requires {@link module: [path]{@link https://nodejs.org/api/path.html}}
1311
* @requires {@link module: [rollup-plugin-re]{@link https://github.com/jetiny/rollup-plugin-re}}
1412
* @requires {@link module: [rollup-plugin-node-resolve]{@link https://github.com/rollup/rollup-plugin-node-resolve}}
1513
* @requires {@link module: [rollup-plugin-terser]{@link https://github.com/TrySound/rollup-plugin-terser}}
1614
*/
1715

18-
const builtins = require( 'rollup-plugin-node-builtins' )
19-
const commonjs = require( 'rollup-plugin-commonjs' )
20-
const json = require( 'rollup-plugin-json' )
21-
const path = require( 'path' )
22-
const replace = require( 'rollup-plugin-re' )
23-
const resolve = require( 'rollup-plugin-node-resolve' )
24-
const terser = require( 'rollup-plugin-terser' ).terser
16+
const packageInfos = require( '../package' )
17+
const commonjs = require( 'rollup-plugin-commonjs' )
18+
const path = require( 'path' )
19+
const replace = require( 'rollup-plugin-re' )
20+
const resolve = require( 'rollup-plugin-node-resolve' )
21+
const terser = require( 'rollup-plugin-terser' ).terser
22+
23+
function _computeBanner ( name, format ) {
24+
25+
const packageName = name || packageInfos.name
26+
let prettyFormat = ''
27+
28+
switch ( format ) {
29+
30+
case 'cjs':
31+
prettyFormat = 'CommonJs'
32+
break
33+
34+
case 'esm':
35+
prettyFormat = 'EsModule'
36+
break
37+
38+
case 'iife':
39+
prettyFormat = 'Standalone'
40+
break
41+
42+
case 'umd':
43+
prettyFormat = 'Universal'
44+
break
45+
46+
default:
47+
throw new RangeError( `Invalid switch parameter: ${format}` )
48+
49+
}
50+
51+
return `console.log('${packageName} v${packageInfos.version} - ${prettyFormat}')`
52+
53+
}
2554

2655
/**
2756
* Will create an appropriate configuration object for rollup, related to the given arguments.
@@ -49,20 +78,21 @@ function CreateRollupConfigs ( options ) {
4978
for ( let envIndex = 0, numberOfEnvs = envs.length ; envIndex < numberOfEnvs ; envIndex++ ) {
5079

5180
const env = envs[ envIndex ]
52-
const prod = ( env.includes( 'prod' ) )
81+
const isProd = ( env.includes( 'prod' ) )
5382
const format = formats[ formatIndex ]
54-
const outputPath = ( prod ) ? path.join( output, `${fileName}.${format}.min.js` ) : path.join( output, `${fileName}.${format}.js` )
83+
const outputPath = ( isProd ) ? path.join( output, `${fileName}.${format}.min.js` ) : path.join( output, `${fileName}.${format}.js` )
5584

5685
configs.push( {
57-
input: input,
58-
external: ( [ 'esm', 'cjs' ].includes( format ) ) ? [
86+
input: input,
87+
external: ( format === 'cjs' ) ? [
5988
'fs',
6089
'path'
6190
] : [],
62-
plugins: [
91+
plugins: [
6392
replace( {
6493
defines: {
65-
IS_REMOVE: prod
94+
IS_REMOVE_ON_BUILD: false,
95+
IS_BACKEND_SPECIFIC: ( format === 'cjs' )
6696
}
6797
} ),
6898
commonjs( {
@@ -71,13 +101,9 @@ function CreateRollupConfigs ( options ) {
71101
resolve( {
72102
preferBuiltins: true
73103
} ),
74-
json( {} ),
75-
( [ 'iife', 'umd' ].includes( format ) ) && builtins( {
76-
fs: true
77-
} ),
78-
prod && terser()
104+
isProd && terser()
79105
],
80-
onwarn: ( { loc, frame, message } ) => {
106+
onwarn: ( { loc, frame, message } ) => {
81107

82108
// Ignore some errors
83109
if ( message.includes( 'Circular dependency' ) ) { return }
@@ -100,7 +126,7 @@ function CreateRollupConfigs ( options ) {
100126

101127
// advanced options
102128
paths: {},
103-
banner: '',
129+
banner: ( isProd ) ? '' : _computeBanner( name, format ),
104130
footer: '',
105131
intro: '',
106132
outro: '',

sources/itee-utils.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
*/
88

99
export * from './cores/_cores'
10-
export * from './file-system/_file-system'
1110
export * from './geomathics/_geomathics'
1211
export * from './physics/_physics'
1312
export * from './testings/_testings'
13+
14+
// #if IS_BACKEND_SPECIFIC
15+
export * from './file-system/_file-system'
16+
// #endif

0 commit comments

Comments
 (0)