It sounds like you could consider using Browserify, combined with babelify
to transpile the files to ES5.
Basically, to bundle all "main.js" files in your tree, you could run the following (assuming a Unix-like OS):
for file in */**/main.js
do
browserify -t [ babelify ] $file > $(dirname $file)/bundle.js
done
(you can put that in a shell script quite easily)
This will create a file called bundle.js
next to the main.js
, which will include the transpiled contents of main.js
, and any of its dependencies (which you load using require()
or import
).
To get babelify
to transpile ES6 to ES5, you need to install some common Babel presets like es2015
, and pass them as argument to babelify
(see this):
browserify -t [ babelify --presets [ es2015 ] ] $file
(or use a .babelrc
file)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…