Configuration

Table of Contents

Place the file union.config.js into the root of your project if you want to configure react-union-scripts.

Configuration file can export either:

  • static JSON object or
  • function.

To the function is passed object that describes flags derived from calling our CLI API:

// example of dynamic union.config.js
module.exports = ({
	target, // custom value
	script, // build, start or test
	app,
	debug,
	proxy,
	verbose,
	noHmr,
	analyze,
}) => ({
	outputMapper: target === 'liferay' ? { js: 'widgets/js' } : {},
});

Resulting configuration can redefine following properties.

devServer

devServer.port : number

Port of proxy server. Defaults to 3300.

devServer.historyApiFallback : boolean

If true, then add connect-history-api-fallback middleware. Defaults to true.

proxy

proxy.port : number

Port of proxy server. Defaults to 3300.

proxy.target : string

Target of proxy

proxy.publicPath : string

Public path of the application. See webpack. Required if you want to run proxy.

outputMapper

Output mapper makes possible further customization of the folder structure that is produced by the build. All paths are relative to the apps[].paths.build directory.

outputMapper.js : string

Path of JavaScript assets. Defaults to static/js.

outputMapper.media : string

Path of media assets. Defaults to static/media.

clean

outputMapper.paths : string

Paths to clean before build. By default equals to [paths.build]

outputMapper.oprions : object

See clean-webpack-plugin

apps

Array of configurations for your applications. Every configuration is merged with above properties. You can rewrite them separately for every application.

For example in the configuration:

module.exports = {
	proxy: { port: 3333 },
	apps: [
		{
			name: 'MyFirstApp',
			proxy: { port: 5000 },
		},
		{ name: 'MySecondApp' },
	],
};

MyFirstApp will use proxy port 5000 and MySecondApp will use common value 3333.

apps[].name : string

Name of your application that is used for both:

  • finding HTML template in ./public directory and
  • naming your bundle file. Required.

apps[].paths.build : string

Path to the build directory. Defaults to <project root>/build/[ApplicationName].

apps[].paths.public : string

Path to public directory. Directory should contain:

  • static assets, that will be copied to the build directory
  • a HTML template that is named according to templateFilename property. Defaults to <project root>/public/[ApplicationName].

apps[].paths.index : string

Path to entry file of a the application. Defaults to <project root>/apps/[ApplicationName].

templateFilename

templateFilename : string

Name of the HTML template. Defaults to index.ejs.

generateTemplate

generateTemplate : boolean

If true, generates template by using html-webpack-plugin. Defaults to true.

generateVendorBundle

generateVendorBundle : boolean

If true, generates separate vendor chunk. Vendors are all dependencies from your package.json. Defaults to true.

vendorBlacklist

'vendorBlackList' : array[string]

List of dependencies that should not be included within vendor chunk. Defaults to [].

mergeWebpackConfig

mergeWebpackConfig : function

If specified, webpack.config generated by react-union-scripts is passed as the argument. Function must return new valid webpack config.

asyncSuffix

['asyncSuffix'](string, array[string], RegExp) Suffix for files to load chunks async. Defaults to widget.

copyToPublicIgnore

copyToPublicIgnore : RegExp

Pattern for files that should not be copied from public folder in build process. Defaults to /\.ejs$/.

workspaces

Workspaces can rewrite default patterns for monorepo matching.

workspaces.widgetPattern : string, array[string], RegExp

Pattern for the widget packages. Defaults to union-widget.

workspaces.appPattern : string, array[string], RegExp

Latter for the app packages. Defaults to union-app.

uglifyOptions

Options for configuration of minifier engine (currently uglify-es).

Supported options: