Reputation: 9279
Now, we can do the following on browsers:
// module.js
var a = 10;
var m = 20;
export {a,a as aa};
export var b = 30;
export function f(){return m;};
export class cl{}
Then on the main HTML file, say, index.html:
<!DOCTYPE html><html><body>
<script type="module">
import {a,b,aa,aa as aaa, f, cl} from "./module.js";
import * as X from "./module.js";
console.log(a,b,aa,aaa,X.aa,X.aaa,f(),cl);
// 10 30 10 10 10 undefined 20 class cl{}
export {a,b as z} from "./module.js";
// re-exports a and b
export * from "./module.js";
// re-exports everything except default
</script>
</body></html>
We can even load an import dynamically with the new ECMASCript2020 syntax (import()).
It makes me wonder whether traditional module bundlers such as webpack, browserify, rollup, AMD, requireJS etc. have become obsolete? Personally I have never used them. I would appreciate it if someone who has used them tells me whether it is absolutely necessary to use them today for the benefits they used to offer.
Upvotes: 1
Views: 1226
Reputation: 658
Loaders AMD are becoming obsolete because people do not use them, with the exception of webpack, that has gained many followers, although webpack itself is not a loader, rather it is a module definition and resource packer with many utilities and is used by frameworks javascript most used (angular, vuejs, react) one of its best features is the development server.
I think webpack is progressing very well, its purpose is not to load modules, it is to optimize loading and development, it is a tool for develop not a runtime library like amd loaders, so it will continue to integrate well into ES2020 since ES is a specification and cannot offer tools that packers offer.
Upvotes: 0
Reputation: 1818
requirejs or other AMD based loaders are still good if you have some pretty old vanilla JS, they still work well. If you are developing some new UI/JS app you can use webpack. ES2020 may not be avilable in all browsers so have to wait till gets supported in major browsers.
Upvotes: 0