1 2 3 4 | let newState = update( this .state, { message: {$set: "Success!" } }); this .setState(newState); |
That additional content can be excluded from the bundled JS by these adjustments:
- Use the "external()" method on browserify to remove it from the bundle
12345
let bundler = browserify({
entries: config.rootJS,
debug:
true
//This provides sourcemapping
})
//Initialising browserify
.external([
'react'
,
'react-addons-update'
,
'react-dom'
,
'react-router'
]);
- Add a shim entry in the package.json file to map a global name to the addon
123456
"browserify-shim"
: {
"react"
:
"global:React"
,
"react-addons-update"
:
"global:React_Addons_Update"
,
"react-dom"
:
"global:ReactDOM"
,
"react-router"
:
"global:ReactRouter"
}
- Create an additional JavaScript file containing the ES2015 addon code transpiled to E5
However, that new bundled file for the addon did not expose a global name that could be used within my custom bundle. The key to exposing this global name proved to be adding the "standalone" parameter in the browserify call (line 6 in the code below).
1 2 3 4 5 6 7 8 9 10 11 12 13 | gulp.task( 'packageReactAddons' , () => { let bundler = browserify({ entries: 'node_modules/react/lib/update.js' , debug: false , standalone: 'React_Addons_Update' }); return bundler.bundle() .on( 'error' , console.error.bind(console)) .pipe(source( 'react_addons_update.js' )) // Pass desired output file name to vinyl-source-stream .pipe(gulp.dest(config.librariesOutputPath)); // Destination for the bundle }) |
No comments:
Post a Comment