Closed thgreasi closed 8 years ago
Any timeline on when this is going to be pushed to npm?
I'm almost made it work with lovalforage :) How about pushing my latest commits on the babel6 branch tonight and if it works for you we can push it to npm during the weekend?
Surprisingly, I have found a strange bug with CallExpression not working with exactly one parameter (it works without or with more than one parameter). The problem appears when trying to emit:
resolve(require('./module/path')); //becomes resolve(); !?!?!?!?
Surprisingly two other alternatives that seems to work are:
resolve(require('./module/path', undefined));
resolve(require(('./module/path')));
@butsjoh just published v2.0.0. I hope that it works for you.
I will try tomorrow :+1:
Seems to be working. Still wondering if it normally should do code splitting or not?
window.initComp = (domEl, props) {
require.ensure([], function() {
var my = require('components/my_component.jsx'),
myComponent = React.createFactory(my.default);
render(myComponent(props), domEl);
}, 'comp');
}
Above code will when running webpack for production produce a seperate file called comp.js where only the code for the component is included.
Not sure if/how this plugin supports this :
window.initComp = (domEl, props) {
System.import('components/my_component.jsx').then(function(my){
myComponent = React.createFactory(my.default);
render(myComponent(props), domEl);
});
}
While the above works there is no way for me to setup code splitting for that file like with require.ensure.
I lost your comment a bit, since I'm not very familiar with require.ensure
.
Would an option that would change commonjs require()
calls to require.ensure()
calls be enough for your use case?
In other words, would you prefer something like this:
new Promise(function (resolve, reject) {
var global = window;
if (typeof global.define === 'function' && global.define.amd) {
global.require(['utilsSerializer'], resolve, reject);
} else if (typeof module !== 'undefined' && (module.exports && typeof require !== 'undefined') ||
typeof module !== 'undefined' && (module.component && (global.require && global.require.loader === 'component'))) {
require.ensure(['./utils/serializer'], function(require) {
resolve(require('./utils/serializer'));
});
} else {
resolve(global['utilsSerializer']);
}
}).then(function(module){
console.log(module);
});
Is the above even correct? Any idea how a rejection could be handled?
Ok, I am confussing you :-1: When i say code splitting i mean in the context of webpack (https://webpack.github.io/docs/code-splitting.html) and not babel. I mixed up your plugin with a webpack plugin. So you can ignore my request.
This is currently under development in the babel6 branch.