Defining global variable for Browserify

Writing Spine = require(‘spine’) in each file is the right way to do. Yet, there are several possibilities by using the global or window object (browserify sets the global object to window, which is the global namespace): in spine.js: global.Spine = module.exports in any other .js file bundled by browserify: global.Spine = require(‘spine’) in a … Read more

Modules vs. Namespaces: What is the correct way to organize a large typescript project?

tl;dr: Do not choose the past. Choose the future: Modules. In early drafts of the ES6 modules specification, there was an inline modules notion, which then has been eliminated in September 2013. However, this notion was already implemented by the TypeScript team, in 2012, with the first beta versions of the language: it was internal … Read more

Disable chrome react DevTools for production

According to an issue on Github, you can add run a single javascript line before react is loaded to prevent it. From #191 of react-devtools <script> window.__REACT_DEVTOOLS_GLOBAL_HOOK__.inject = function () {} </script> Then, you may consider wrapping this with your environment condition, like that you could do sth like below in your server side rendering. … Read more

How do I use Browserify with external dependencies?

You can achieve that by using browserify-shim. Assuming that you’ve got a module named mymodule.js that depends on jQuery in the global scope with the following contents: var $ = require(‘jQuery’); console.log(typeof $); Install browserify-shim: npm install browserify-shim –save-dev In package.json file, tell browserify to use browserify-shim as a transform: { “browserify”: { “transform”: [ … Read more

Is there a way to render multiple React components in the React.render() function?

Since the React v16.0 release you can render an array of components without wrapping items in an extra element when you are inside a component: render() { return [ <li key=”one”>First item</li>, <li key=”two”>Second item</li>, <li key=”three”>Third item</li>, <li key=”four”>Fourth item</li>, ]; } Remember only to set the keys. UPDATE Now from the 16.2 version … Read more

How to import part of object in ES6 modules

Unfortunately import statements does not work like object destructuring. Curly braces here mean that you want to import token with this name but not property of default export. Look at this pairs of import/export: //module.js export default ‘A’; export var B = ‘B’; //script.js import A from ‘./a.js’; //import value on default export import {B} … Read more

require is not defined error with browserify

The “require” function is only available in the “https://stackoverflow.com/questions/28696511/bundle.js” script context. Browserify will take all the script files necessary and put them into the “https://stackoverflow.com/questions/28696511/bundle.js” file, so you should only have to include “https://stackoverflow.com/questions/28696511/bundle.js” in the HTML file, not the “script.js” file.