Comments (6)
6to5 has a commonInterop module formatter which in 2.0.0 is going to be the default. You can pass this option to 6to5 like so:
browserify().transform(to5ify.configure({ modules: "commonInterop" }));
or
$ browserify -t [ 6to5ify --modules commonInterop ]
from babelify.
For those of you who find this later and want to know more... this is what I ended up with using Gulp:
...
var browserify = require('browserify');
var envify = require('envify');
var reactify = require('reactify');
var to5ify = require('6to5ify');
...
var bundler = browserify({
basedir: __dirname,
debug: (process.env.NODE_ENV === 'development'),
entries: './src/client/client.js',
cache: {},
packageCache: {},
fullPaths: watch
})
.add(require.resolve("6to5/polyfill"))
.transform(envify)
.transform(to5ify.configure({
modules: 'commonInterop'
}))
.transform(reactify);
from babelify.
@ruswerner modules
should be a string, not an array. I'm not even sure how that works if it somehow does.
from babelify.
@sebmck It certainly does work as an array:
when using
.transform(to5ify.configure({
}))
this
import React from 'react';
becomes this
var React = require('react')["default"];
Whereas when using this:
.transform(to5ify.configure({
modules: ['commonInterop']
}))
it becomes this
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var React = _interopRequire(require('react'));
Did I find a bug?
from babelify.
@sebmck OK. So I traced through the 6to5 code and you are correct in thinking how this could possibly work. It doesn't make sense, however in nodejs, this happens:
var hash = { commonInterop: 'yesplease' };
console.log(hash['commonInterop']); // prints yesplease
console.log(hash[['commonInterop']]); // also prints yesplease
I have been writing JavaScript for a long time and had no idea this works; it's either a typecasting bug, or something else about JS that makes no sense.
from babelify.
Ah yeah, that'e make sense. It's type casting toString because only all
keys are strings.
On Thursday, 18 December 2014, ruswerner [email protected] wrote:
@sebmck https://github.com/sebmck OK. So I traced through the 6to5 code
and you are correct in thinking how this could possibly work. It doesn't
make sense, however in nodejs, this happens:var hash = { commonInterop: 'yesplease' };
console.log(hash['commonInterop']); // prints yesplease
console.log(hash[['commonInterop']]); // also prints yespleaseI have been writing JavaScript for a long time and had no idea this works;
it's either a typecasting bug, or something else about JS that makes no
sense.Reply to this email directly or view it on GitHub
#16 (comment).
Sebastian McKenzie
from babelify.
Related Issues (20)
- Babel 7 Stable Released HOT 8
- Bundling hyperhtml-element with browserify/babelify not working
- transform-arrow-functions being ignored for external packages? HOT 5
- TypeError: extensions.indexOf is not a function
- TypeError: Cannot read property 'canCompile' of undefined HOT 5
- How to get babelify && preset-env to convert 'const' HOT 3
- Boolean options fail (e.g. --compact true) HOT 1
- usage of babel/polyfills HOT 4
- Not working "Why aren't files in node_modules being transformed?" HOT 14
- Use a Bundler for Development? HOT 1
- tsify + babelify + browserify with threejs modules: SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' (9:0) HOT 17
- Is it possible to disable asyncToGenerator? HOT 2
- TypeError: Cannot read property 'arrayify' of undefined HOT 2
- Is this incompatible with Babel 7? HOT 3
- If I don't specify any Babel plugins or presets, what exactly should happen? HOT 6
- Continued problems with issue #103 ('import' and 'export' may appear only with 'sourceType: module') HOT 4
- How to use with globally installed browserify? HOT 1
- No source being transformed HOT 1
- babelify + gulp with threejs modules: SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' (9:0)
- 'import' and 'export' may appear only with 'sourceType: module' (14:0)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from babelify.