renative icon indicating copy to clipboard operation
renative copied to clipboard

Webpack configs should be merged using webpack-merge

Open mikiest opened this issue 3 years ago • 3 comments

Describe the bug When using platforms.web.webpackConfig.extend to extend some of the webpack configs for web, the webpack configs are currently merged using a spread operator ...extend. This means any object we specify in platforms.web.webpackConfig.extend, for example resolve, will override the default equivalent entirely instead of being merged with it.

To Reproduce

  1. In renative.json, add the following:
"platforms": {
	"web": {
		"webpackConfig": {
			"extend": {
				"resolve": {
					"alias": {
						  "my-module": "some_path"
					}
				}
			}
		}
	}
}
  1. The build won't succeed, for example most react-native modules will not be found anymore, TypeScript file extensions would not necessarily be included, etc. This is a result of extensions and other aliases being removed since spreading the content of the extend object above will override entirely its properties and not deep merge them.

Expected behavior All webpack configs are always merged using webpack-merge so that configs can be extended and not overriden.

Screenshots or copy&paste This is where I believe using webpack-merge would be better, for example, in platformBuilds/<projectName>_web/webpack.config.dev.js:

module.exports = {
    entry: C.entry,
    devServer: C.devServer,
    output: C.output,
    module: {
        rules: [C.Rules.babel, C.Rules.css, C.Rules.image, C.Rules.fonts, C.Rules.sourcemap],
    },
    plugins,
    resolve: {
        symlinks: false,
        extensions: C.extensions,
        alias: C.aliases,
    },
    ...config.extend || {}	// this will override `resolve` entirely if `config.extend` contains the same property
};

Desktop:

  • OS: OSX
  • Node Version: v10.16.3
  • RNV Version: 0.31.3

mikiest avatar Apr 06 '21 18:04 mikiest

@mikiest thanks for reporting this issue. Is this still reproduced on latest rnv version?

pauliusguzas avatar May 19 '23 07:05 pauliusguzas

  1. test rn-web engine sanity
  2. demonstrate webpack override and document
  3. if 1 and 2 ok then we can close this and open a new ticket for proper extendability of webpack config

mihaiblaga89 avatar Feb 12 '24 08:02 mihaiblaga89

@mikiest should be fixed with 1.0.0-rc.12

pauliusguzas avatar Mar 05 '24 12:03 pauliusguzas