Im using the lib sucrase
to use ES6 modules in NodeJS(import/export
) and i'm using the follow command to generate a build of my project in commonJ:
sucrase ./src -d ./build --transforms imports
where ./src
is my project folder and ./build
is the output. When the process is finished i have a build
folder with my javascripts
files converted to commonJS but the assets files and every no-JS files are moved to this build
folder, like images and css files in public
directory or PUG files in views
, only the JS files and directories are moved. I dont know if is possible do this with sucrase
cause i've already read the doc, but maybe its possible do with another lib(sucrase with other lib).
My project structure(src
)
│ app.js
│
├───public
│ │
│ ├───images
│ │ some-image.png
│ │
│ ├───javascripts
│ │ script.js
│ │
│ └───stylesheets
│ styles.min.css
│
├───routes
│ index.js
│
└───views
│ index.pug
│ layout.pug
│
└───parts
footer.pug
header.pug
My project structure after converted(build
)
│ app.js
│
├───public
│ │
│ ├───images
│ │
│ ├───javascripts
│ │ script.js
│ │
│ └───stylesheets
│
├───routes
│ index.js
│
└───views
└───parts
I read sucrase document and found that ONLY support load JS files (JSX, TS, etc). If you want to load another kind of files, use file-loader.
Sucrase also offers a package called @sucrase/webpack-loader. You can give it a try, but I'm not sure it supports to load images, non-JS files and so on.
Last but not least, sucrase
documentation is not great, and I highly recommend not using it because you will have trouble with it community like this. Use Webpack, Babel or parcel instead if you want to deep dive into bundler. For modern approach for example with ReactJS, I higly recommend using gatsby to forget all things about bundler, you totally can move your react app into gatsby easily.
Maybe this might not help you resolve problem, but I hope I can give you a picture on your problem. Sharing is more important thing. Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With