@@ -44,16 +44,23 @@ function checkNameClashes (icons) {
4444
4545 fse . removeSync ( path . join ( __dirname , 'package' ) )
4646 fse . mkdirpSync ( path . join ( __dirname , 'package' , 'light' ) )
47+ fse . removeSync ( path . join ( __dirname , 'package' , 'esm' ) )
48+ fse . mkdirpSync ( path . join ( __dirname , 'package' , 'esm' , 'light' ) )
4749
4850 for ( const { name, filename, svgPath } of icons ) {
4951 const code = `import createIcon from './util/createIcon'
5052 export default createIcon('${ svgPath } ', '${ name } ')
5153 `
5254
53- // commonjs module syntax
55+ // es module
56+ fse . writeFileSync ( path . join ( __dirname , 'package' , 'esm' , `${ filename || name } .js` ) , babel . transform ( code , {
57+ presets : [ '@babel/preset-react' , [ '@babel/preset-env' , { modules : false } ] ] ,
58+ compact : process . env . NODE_ENV === 'production'
59+ } ) . code )
60+
61+ // commonjs module
5462 fse . writeFileSync ( path . join ( __dirname , 'package' , `${ filename || name } .js` ) , babel . transform ( code , {
5563 presets : [ '@babel/preset-react' , '@babel/preset-env' ] ,
56- plugins : [ '@babel/plugin-proposal-class-properties' ] ,
5764 compact : process . env . NODE_ENV === 'production'
5865 } ) . code )
5966
@@ -67,10 +74,15 @@ function checkNameClashes (icons) {
6774 export default createIcon('${ svgPath } ', '${ name } ')
6875 `
6976
70- // commonjs module syntax
77+ // es module
78+ fse . writeFileSync ( path . join ( __dirname , 'package' , 'esm' , 'light' , `${ filename || name } .js` ) , babel . transform ( code , {
79+ presets : [ '@babel/preset-react' , [ '@babel/preset-env' , { modules : false } ] ] ,
80+ compact : process . env . NODE_ENV === 'production'
81+ } ) . code )
82+
83+ // commonjs module
7184 fse . writeFileSync ( path . join ( __dirname , 'package' , 'light' , `${ filename || name } .js` ) , babel . transform ( code , {
7285 presets : [ '@babel/preset-react' , '@babel/preset-env' ] ,
73- plugins : [ '@babel/plugin-proposal-class-properties' ] ,
7486 compact : process . env . NODE_ENV === 'production'
7587 } ) . code )
7688
@@ -79,10 +91,10 @@ function checkNameClashes (icons) {
7991 ` )
8092 }
8193
82- const generateIndexFiles = ( destination , icons ) => {
83- // es2015 module syntax
94+ const generateIndexFiles = ( destination , esmDestination , icons ) => {
95+ // es module
8496 const allExports = icons . map ( ( { name, filename } ) => `export { default as ${ name } } from './${ filename || name } '` ) . join ( '\n' )
85- fse . writeFileSync ( path . join ( destination , 'index.es .js' ) , allExports )
97+ fse . writeFileSync ( path . join ( esmDestination , 'index.js' ) , allExports )
8698
8799 // typescript index definition (looks exactly the same)
88100 fse . writeFileSync ( path . join ( destination , 'index.d.ts' ) , allExports )
@@ -94,18 +106,26 @@ function checkNameClashes (icons) {
94106 } ) . code )
95107 }
96108
97- generateIndexFiles ( path . join ( __dirname , 'package' ) , icons )
98- generateIndexFiles ( path . join ( __dirname , 'package' , 'light' ) , lightIcons )
109+ generateIndexFiles ( path . join ( __dirname , 'package' ) , path . join ( __dirname , 'package' , 'esm' ) , icons )
110+ generateIndexFiles ( path . join ( __dirname , 'package' , 'light' ) , path . join ( __dirname , 'package' , 'esm' , 'light' ) , lightIcons )
99111
100112 // createIcon function
101113 fse . mkdirSync ( path . join ( __dirname , 'package' , 'util' ) )
114+ fse . mkdirSync ( path . join ( __dirname , 'package' , 'esm' , 'util' ) )
102115 fse . writeFileSync (
103116 path . join ( __dirname , 'package' , 'util' , 'createIcon.js' ) ,
104117 babel . transform ( fse . readFileSync ( path . join ( __dirname , 'src' , 'util' , 'createIcon.js' ) ) , {
105118 presets : [ [ '@babel/preset-react' , { runtime : "automatic" } ] , '@babel/preset-env' ] ,
106119 compact : process . env . NODE_ENV === 'production'
107120 } ) . code
108121 )
122+ fse . writeFileSync (
123+ path . join ( __dirname , 'package' , 'esm' , 'util' , 'createIcon.js' ) ,
124+ babel . transform ( fse . readFileSync ( path . join ( __dirname , 'src' , 'util' , 'createIcon.js' ) ) , {
125+ presets : [ [ '@babel/preset-react' , { runtime : "automatic" } ] , [ '@babel/preset-env' , { modules : false } ] ] ,
126+ compact : process . env . NODE_ENV === 'production'
127+ } ) . code
128+ )
109129
110130 // update readme
111131 const mdiVersion = require ( path . join ( require . resolve ( '@mdi/js' ) , '..' , '..' , 'package.json' ) ) . version
0 commit comments