-
Notifications
You must be signed in to change notification settings - Fork 200
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
Support header/footer variants for javascript targets in ksc #267
Comments
LGTM. We'd likely use Can you clarify:
var TestKsy = (function() {
function TestKsy(_io, _parent, _root) {
this._io = _io;
this._parent = _parent;
this._root = _root || this;
this._read();
}
TestKsy.prototype._read = function() {
// ...
}
return TestKsy;
})();
// Export for amd environments
if (typeof define === 'function' && define.amd) {
define('TestKsy', [], function() {
return TestKsy;
});
}
// Export for CommonJS
if (typeof module === 'object' && module && module.exports) {
module.exports = TestKsy;
} |
As far as I understand, generally we could do the following formats:
|
CJS is CommonJS. @fallenoak could you confirm that webpack supports UMD works AFAIK in every runtime environment (browsers, node, etc). So Problem comes when you try to preprocess these files, and not run them. But in that case I'd expect every modern tool (as preprocess tools are usually young tools) to support We only need CJS (commonjs) support if a wide-spread preprocess tool does not support ES6 modules yet. Of course if it's easier to implement support for all of them than arguing what to support, then ignore my comments and implement all options. |
Well, at the very least I assume that whole JavaScript world is kind of fragmented in that respect. UMD is meant to be "one and true", but ES6 is probably even more "true", if you're talking about future. So, yeah, I guess it's easier for us to just implement them all and let the user decide (and leave UMD as a sane default that will work for 95..99% of users). |
Correct, I meant CommonJS earlier. I'll verify that webpack 2 supports ES6 modules later today. UMD is really more of a bridge format meant to deal with fragmentation until various runtimes all get native ES6 support. It's a good default, I think, but it creates unnecessary cruft for environments that support ES6 modules natively. |
It looks like webpack Based on this, I'd suggest we only need to support 2 or 3 possible options:
And to clarify, ES6 should avoid any wrapper functions: // any relevant import statements here
function TestKsy(_io, _parent, _root) {
this._io = _io;
this._parent = _parent;
this._root = _root || this;
this._read();
}
TestKsy.prototype._read = function() {
// ...
}
export default TestKsy; |
Do I get it correctly that, in theory, UMD has both AMD and CommonJS inside it? |
Yes. If you run the code, then UMD works exactly the same as CJS or AMD (UMD detects which environment does it run and behaves just like that). The problem comes when these tools don't run the code, but try to parse it to AST or I don't know and they are searching for simple |
Um, ok. So, let's do |
While working on tidying up
kaitai-struct-loader
, it's dawned on me that the UMD header/footer isn't necessary within webpack.Ideally, the output for a
ksy
being compiled for use in webpack would look like vanilla CJS:Perhaps we could signal this with a command line flag?
--js-module-format cjs
for example?Another useful variant would be ES6 modules (which, ostensibly, webpack 2 can also consume):
Maybe
--js-module-format es6
?The text was updated successfully, but these errors were encountered: