@@ -11,7 +11,7 @@ const DIST_PATH = path.resolve(__dirname, "dist");
1111export const extensions = [ ".js" , ".jsx" ] ;
1212
1313// Compile index & compile separately every elements exported by it.
14- const input = Object . fromEntries ( [
14+ const input = [
1515 [ "neeto-icons" , "./generate/icons/index.js" ] ,
1616 [ "neeto-logos" , "./generate/logos/index.js" ] ,
1717 [ "app-icons" , "./generate/app-icons/index.js" ] ,
@@ -21,36 +21,40 @@ const input = Object.fromEntries([
2121 const componentName = path . basename ( componentPath ) ;
2222 return [ componentName , componentPath ] ;
2323 } ) ,
24- ] ) ;
24+ ] ;
2525
2626
2727const formats = [ "esm" , "cjs" ] ;
2828
29- const output = formats . map ( ( format ) => ( {
30- format,
31- sourcemap : true ,
32- dir : path . join ( DIST_PATH ) ,
33- } ) ) ;
29+ const plugins = [
30+ // generate components
31+ generateComponents ( componentGenerationConfig ) ,
32+ // Analyze created bundle.
33+ analyze ( ) ,
34+ // Resolve source files.
35+ resolve ( { browser : true , extensions } ) ,
36+ // Resolve commonjs dependencies.
37+ commonjs ( { include : / n o d e _ m o d u l e s / } ) ,
38+ babel ( {
39+ extensions,
40+ exclude : / n o d e _ m o d u l e s / ,
41+ presets : [
42+ [ "@babel/preset-env" , { targets : "defaults" } ] ,
43+ "@babel/preset-react" ,
44+ ] ,
45+ } ) ,
46+ ] ;
3447
35- export default {
36- input,
37- output,
38- plugins : [
39- // generate components
40- generateComponents ( componentGenerationConfig ) ,
41- // Analyze created bundle.
42- analyze ( ) ,
43- // Resolve source files.
44- resolve ( { browser : true , extensions } ) ,
45- // Resolve commonjs dependencies.
46- commonjs ( { include : / n o d e _ m o d u l e s / } ) ,
47- babel ( {
48- extensions,
49- exclude : / n o d e _ m o d u l e s / ,
50- presets : [
51- [ "@babel/preset-env" , { targets : "defaults" } ] ,
52- "@babel/preset-react" ,
53- ] ,
54- } ) ,
55- ] ,
56- } ;
48+ const getOutputFilename = ( name , format ) =>
49+ format === "esm" ? `dist/${ name } .js` : `dist/${ name } .cjs.js`
50+
51+ export default input . map ( ( [ filename , pathname ] ) => ( {
52+ input : pathname ,
53+ plugins,
54+ output : formats . map ( ( format ) => ( {
55+ assetFileNames : "[name][extname]" ,
56+ file : getOutputFilename ( filename , format ) ,
57+ format,
58+ sourcemap : true ,
59+ } ) )
60+ } ) ) ;
0 commit comments