问题
I am new to all ES6 transpiling and I was planning on using BabelJS.
Is there a way to concatenate scripts with there imports in babelJS
I have the following
home.js imports home/home-navbar and home/home-slider
I want the output to contain both home/home-navbar and home/home-slider but put them all in one file home.js
Can I do this in BabelJS? and if not what would be the proper way to do it?
回答1:
Can I do this in BabelJS?
No, not yet.
what would the proper way to do it?
Not sure about the proper way, but there are alternatives. Tools like browserify and esperanto compute module dependencies and bundle them into a single files (or multiple if desired).
Depending on your specific use case you could also write a simple script that concatenates all files.
回答2:
Babel runs in the client, and it doesn't actually alter system files, which you would need a server for.
If you want to share resources, you can always transport objects via the shared
window
object
class MyClass {
constructor (config) {
super(config);
this.config = config;
}
}
window.MyClass = MyClass;
var MyClass = window.MyClass;
class ExtendedClass extends MyClass {
constructor (config) {
super(config);
console.log(this.config); // from MyClass
}
}
来源:https://stackoverflow.com/questions/31015250/concatenate-imports-in-modules-in-babeljs