babel CLI copy nonjs files

Babel has the copy files option for this: babel src –out-dir lib –copy-files Note: It is true that babels primary purpose is to process javascript files, but babel’s big suite of tools these day often makes it unnecessary to go for more complex build script setups as gulp and alike. A gulp-less setup could be … Read more

ES6 `export * from import`?

Yes, ES6 supports directly exporting imported modules: export { name1, name2, …, nameN } from …; export {FooAction, BarAction} from ‘./action_creators/index.js’ You can also re-export all exports of the imported module using the * syntax: export * from …; export * from ‘./action_creators/index.js’; More info on MDN.

Webpack babel 6 ES6 decorators

This Babel plugin worked for me: https://github.com/loganfsmyth/babel-plugin-transform-decorators-legacy npm i –save-dev babel-plugin-transform-decorators-legacy .babelrc { “presets”: [“es2015”, “stage-0”, “react”], “plugins”: [ [“transform-decorators-legacy”], // … ] } or Webpack { test: /\.jsx?$/, loader: ‘babel’, query: { cacheDirectory: true, plugins: [‘transform-decorators-legacy’ ], presets: [‘es2015’, ‘stage-0’, ‘react’] } } React Native With react-native you must use the babel-preset-react-native-stage-0 plugin instead. … Read more

Babel 7 – ReferenceError: regeneratorRuntime is not defined

Updated Answer: If you are using Babel 7.4.0 or newer, then @babel/polyfill has been deprecated. Instead, you will want to use the following at the top of your main js file (likely index.js or similar): import “core-js/stable”; import “regenerator-runtime/runtime”; Install these packages either with npm: npm install –save core-js npm install –save regenerator-runtime or with … Read more

Babel file is copied without being transformed

Babel is a transformation framework. Pre-6.x, it enabled certain transformations by default, but with the increased usage of Node versions which natively support many ES6 features, it has become much more important that things be configurable. By default, Babel 6.x does not perform any transformations. You need to tell it what transformations to run: npm … Read more

Dynamically add child components in React

You need to pass your components as children, like this: var App = require(‘./App.js’); var SampleComponent = require(‘./SampleComponent.js’); ReactDOM.render( <App> <SampleComponent name=”SomeName”/> <App>, document.body ); And then append them in the component’s body: var App = React.createClass({ render: function() { return ( <div> <h1>App main component! </h1> { this.props.children } </div> ); } }); You … Read more

Service mocked with Jest causes “The module factory of jest.mock() is not allowed to reference any out-of-scope variables” error

You need to store your mocked component in a variable with a name prefixed by “mock”. This solution is based on the Note at the end of the error message I was getting. Note: This is a precaution to guard against uninitialized mock variables. If it is ensured that the mock is required lazily, variable … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)