1- import { get , isString , merge } from 'lodash' ;
1+ import { get , isString , mergeWith } from 'lodash' ;
22import babel from 'rollup-plugin-babel' ;
33import camelcase from 'camelcase' ;
44import commonjs from 'rollup-plugin-commonjs' ;
@@ -19,14 +19,18 @@ import translationXML from './plugins/translation-xml';
1919
2020const defaultName = path . basename ( process . cwd ( ) ) ;
2121
22+ const mergeConfig = ( config , customConfig ) => mergeWith ( config , customConfig , ( obj , src ) => (
23+ Array . isArray ( obj ) && Array . isArray ( src ) ? src . concat ( obj ) : undefined
24+ ) ) ;
25+
2226const getLanguages = ( pluginsOpts ) => {
2327 if ( isString ( process . env . LANGUAGES ) ) {
2428 return process . env . LANGUAGES . split ( '-' ) ;
2529 }
2630 return get ( pluginsOpts , 'translations.languages' ) ;
2731} ;
2832
29- const generateConfig = ( opts , pluginsOpts ) => Object . assign ( {
33+ const generateConfig = ( opts , pluginsOpts ) => mergeConfig ( {
3034 plugins : [
3135 peerdeps ( ) ,
3236 html ( ) ,
@@ -74,15 +78,15 @@ const generateConfig = (opts, pluginsOpts) => Object.assign({
7478 ] ,
7579} , opts ) ;
7680
77- const cjs = ( opts , pluginsOpts ) => generateConfig ( merge ( {
81+ const cjs = ( opts , pluginsOpts ) => generateConfig ( mergeConfig ( {
7882 output : {
7983 dir : './dist/cjs' ,
8084 format : 'cjs' ,
8185 sourcemap : true ,
8286 } ,
8387} , opts ) , pluginsOpts ) ;
8488
85- const umd = ( opts , pluginsOpts ) => generateConfig ( merge ( {
89+ const umd = ( opts , pluginsOpts ) => generateConfig ( mergeConfig ( {
8690 inlineDynamicImports : true ,
8791 output : {
8892 name : defaultName ,
@@ -92,15 +96,15 @@ const umd = (opts, pluginsOpts) => generateConfig(merge({
9296 } ,
9397} , opts ) , pluginsOpts ) ;
9498
95- const es = ( opts , pluginsOpts ) => generateConfig ( merge ( {
99+ const es = ( opts , pluginsOpts ) => generateConfig ( mergeConfig ( {
96100 output : {
97101 dir : './dist/esm' ,
98102 format : 'es' ,
99103 sourcemap : true ,
100104 } ,
101105} , opts ) , pluginsOpts ) ;
102106
103- const iife = ( opts , pluginsOpts ) => generateConfig ( merge ( {
107+ const iife = ( opts , pluginsOpts ) => generateConfig ( mergeConfig ( {
104108 inlineDynamicImports : true ,
105109 output : {
106110 name : camelcase ( defaultName ) ,
@@ -111,10 +115,10 @@ const iife = (opts, pluginsOpts) => generateConfig(merge({
111115} , opts ) , pluginsOpts ) ;
112116
113117const config = ( globalOpts = { } , pluginsOpts = { } ) => ( {
114- cjs : ( opts = { } ) => cjs ( merge ( opts , globalOpts ) , pluginsOpts ) ,
115- es : ( opts = { } ) => es ( merge ( opts , globalOpts ) , pluginsOpts ) ,
116- iife : ( opts = { } ) => iife ( merge ( opts , globalOpts ) , pluginsOpts ) ,
117- umd : ( opts = { } ) => umd ( merge ( opts , globalOpts ) , pluginsOpts ) ,
118+ cjs : ( opts = { } ) => cjs ( mergeConfig ( opts , globalOpts ) , pluginsOpts ) ,
119+ es : ( opts = { } ) => es ( mergeConfig ( opts , globalOpts ) , pluginsOpts ) ,
120+ iife : ( opts = { } ) => iife ( mergeConfig ( opts , globalOpts ) , pluginsOpts ) ,
121+ umd : ( opts = { } ) => umd ( mergeConfig ( opts , globalOpts ) , pluginsOpts ) ,
118122} ) ;
119123
120124config . plugins = {
0 commit comments