Cannot override Uglify config
Current Behavior
Following the example, when I add new webpack.optimize.UglifyJsPlugin() to the plugins list, I get the following error:
ERROR Error running yarn run ios:haul -- --platform ios
TypeError: Cannot read property 'replace' of undefined
at normalizeBackSlashDirection (/Users/s/workspace/flutter/nativeapp/node_modules/webpack/lib/RequestShortener.js:15:16)
at new RequestShortener (/Users/s/workspace/flutter/nativeapp/node_modules/webpack/lib/RequestShortener.js:25:15)
at UglifyJsPlugin.apply (/Users/s/workspace/flutter/nativeapp/node_modules/webpack/node_modules/uglifyjs-webpack-plugin/dist/index.js:39:27)
at Resolver.apply (/Users/s/workspace/flutter/nativeapp/node_modules/tapable/lib/Tapable.js:375:16)
at /Users/s/workspace/flutter/nativeapp/node_modules/enhanced-resolve/lib/ResolverFactory.js:249:12
at Array.forEach (<anonymous>)
at Object.exports.createResolver (/Users/s/workspace/flutter/nativeapp/node_modules/enhanced-resolve/lib/ResolverFactory.js:248:10)
at WebpackOptionsApply.process (/Users/s/workspace/flutter/nativeapp/node_modules/webpack/lib/WebpackOptionsApply.js:283:47)
at webpack (/Users/s/workspace/flutter/nativeapp/node_modules/webpack/lib/webpack.js:37:48)
at Object.start [as action] (/Users/s/workspace/flutter/nativeapp/node_modules/haul/src/commands/start.js:99:20)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
at Function.Module.runMain (module.js:611:11)
at startup (bootstrap_node.js:158:16)
at bootstrap_node.js:598:3
error Command failed with exit code 1.
Looking at https://stackoverflow.com/questions/43884201/uglify-cannot-read-property-reset-of-undefined#44639583 I thought the issue might be related to an unsupported version of uglify, but none of the suggestions mentioned worked for me (still got the same error).
Expected Behavior
It should be possible to override the Uglify options set in the defaults https://github.com/callstack/haul/blob/18ec4180716cbcfa6c3441643b9614953d4ac3ad/src/utils/makeReactNativeConfig.js#L158
Haul Configuration (webpack.haul.js)
const webpack = require('webpack')
module.exports = ({ platform }, defaults) => ({
entry: `./index.${platform}.js`,
resolve: {
...defaults.resolve,
plugins: [
...defaults.resolve.plugins,
new webpack.optimize.UglifyJsPlugin({ mangle: false }),
]
},
});
Your Environment
| software | version |
|---|---|
| Haul | v1.0.0-beta.7 |
| react-native | 0.48.4 |
| node | v8.4.0 |
| npm or yarn | yarn 0.23.4 |
That won't override the plugin, it'll add another instance if the plugin. You have to remove the old instance first if you want to add a different instance.
@satya164 if I don't add defaults to the plugins array (defaults.resolve.plugins are just empty objects, weirdly enough), I still get the same error.
Hmm, perhaps I'm misunderstanding how the webpack.haul.js file is getting processed; I'll try to look at the code more...
I understand the pain of filtering out the original plugin and replacing with your own config, but it's definitely possible with Haul and I think we should close this as per @satya164 comment.
Add uglifyOptions like this:
import {createWebpackConfig} from 'haul';
...
export default {
webpack: env => {
const config = createWebpackConfig({
entry: './src/index.ts',
})(env);
...
if (config.optimization && config.optimization.minimize) {
config.optimization.minimizer[0].options.uglifyOptions.mangle = {safari10: true};
}
return config;
}
};