-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide es module template #76
Comments
Can you provide some reference links to the items you have mentioned (ES2015 modules, webpack 3 scope hoisting, etc...)? This way we are (ahem) on the same page regarding details. |
Sure, gonna do that later today. Thanks for the answer. |
@jhamlet
|
@Andarist What needs to be done in the output string to make it compatible with es2015 modules? |
@jhamlet basically such change should be done imho module.exports = R.curry(function stringify (opts, tree) {
var displayName = opts.displayName;
var preamble = [
- 'var React = require(\'react\');',
+ 'import React from \'react\';',
'',
- 'function ' + displayName + ' (props) {',
+ 'export default function ' + displayName + ' (props) {',
];
var postamble = [
'}',
'',
- displayName + '.displayName = ' + JSON.stringify(displayName) + ';',
- '',
displayName + '.defaultProps = ' + JSON.stringify(tree.props || {}) + ';',
- '',
- 'module.exports = ' + displayName + ';',
- '',
- displayName + '.default = ' + displayName + ';',
''
];
return preamble.
concat([fromObject(tree, true)]).
concat(postamble).
join('\n');
}); but probably which version of the module is emitted should be based on a configuration or deduced from other plugin's config - If that is not possible a simple option in the |
This doesn't seem to provide much bang for the amount of work that would have to be done adding options, checking babel options, and what-not. This might be a situation where an additional loader can be used in the pipeline utilizing |
The bang here is smaller output in people's bundles, less bytes shipped over the wire is always nice to have in my opinion. Checking babel's options was just an idea, surely more complex and im not sure if even doable. Second way - just adding a new option should be pretty easy and not time-consuming at all. I can provide a PR for this if you give a green light for the idea. Using Even if you dont feel its much of a bang, I feel its a right direction even if only because of the fact that |
By bang, I meant that nothing is going to be stripped out with tree shaking since there is only one export in the generated module. And Regarding scope hoisting (module concatenation) : I still do not see what we are getting there -- this just makes sure you only ever import a module once. In any other code splits, those just use a function to return the module from another split. So, actually you are increasing execution time (fractionally) with that extra function invocation. One of the goals with the 0.4.x version of I agree it is a minor change to start using I would rather wait until |
Actually scope hoisting can be used on its own without code-splitting. Example output without scope hoisting used: // module
"./path/to/icon.svg": (function(module, exports, __webpack_require__) {
"use strict";
function IconComponent() {}
module.exports = IconComponent;
})
// importing module
var __WEBPACK_IMPORTED_MODULE_2_assets_minimize_svg__ = __webpack_require__("./path/to/icon.svg") Each module - so each svg icon - is wrapped in a closure by webpack and need to be retrieved for usage in runtime from the giant object/array of modules. Whereas function IconComponent$1() {} |
That second example does make a bit of sense... but, it isn't really buying much. Especially if the module invocation is not cached (it is hard to see what is going on in the I am willing to look at anything you come up with, and anything that requires transpilation, or configuration for such, will be suspect (more moving parts, likely leading to future headaches). I will be far more convinced of changes if you can come up with some samples that demonstrate quantitatively how much can be saved (in bytes, as well as execution time). NOTE: Not trying to be a pain. I am just not convinced this is all that valuable at this point in time. ;-j |
Making your transform produce commonjs also causes extra work on the importing side -- if you import with No checking at all for babel settings or external config is necessary as webpack supports |
Currently the loader is outputting cjs format, we should support both cjs and es2015 modules - probably based on the webpack's + babel versions used.
Why this is important?
This prevents webpack3 from scope hoisting generated components.
If we settle how this should be solved I can offer my help with the implementation.
The text was updated successfully, but these errors were encountered: