Coder Social home page Coder Social logo

Comments (6)

sebmck avatar sebmck commented on May 21, 2024

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.

ruswerner avatar ruswerner commented on May 21, 2024

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.

sebmck avatar sebmck commented on May 21, 2024

@ruswerner modules should be a string, not an array. I'm not even sure how that works if it somehow does.

from babelify.

ruswerner avatar ruswerner commented on May 21, 2024

@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.

ruswerner avatar ruswerner commented on May 21, 2024

@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.

sebmck avatar sebmck commented on May 21, 2024

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 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.

Reply to this email directly or view it on GitHub
#16 (comment).

Sebastian McKenzie

from babelify.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.