Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can Babel be used without bundler, but with a dev-experience similar to webpack?

I'm trying to build a new project with ES6 modules without bundling. I still want to use babel-7 to translate TypeScript and JSX to JS. I find it hard to figure out how to set up a development-server for it. I couldn't find any kind of "babel-dev-server" that works similar to webpack-dev-server (hot-module-reloading, browser-sync, file-watcher).

One possibility would be to use browser sync as a static server on e.g. dist and run something like babel src --out-dir dist --watch in parallel. But this excludes hot-reloading and seems a bit clumsy to me. Besides, it would still be useful for build- and dev-steps if you could give the JS-files a hash to control caching better. Or can I configure a build-tool like webpack so that it doesn't perform bundling but still performs some transformations (like putting the hashs in the filenames in imports)?

like image 345
Putzi San Avatar asked Oct 14 '18 18:10

Putzi San


People also ask

Can Babel work without webpack?

If you just want to get started on React real quick and you don't mind using require or import in your code, then babel could be enough to jump start your React project. Say for example that all your javascript files are in the ./src folder, you can bundle them into one file with this command.

How is Babel different from webpack?

"Modern Javascript works with all browsers", "Open source" and "Integration with lots of tools" are the key factors why developers consider Babel; whereas "Most powerful bundler", "Built-in dev server with livereload" and "Can handle all types of assets" are the primary reasons why Webpack is favored.

Is Babel a dev dependency?

Development dependencies are intended as development-only packages, that are unneeded in production. For example testing packages, webpack or Babel. When you go in production, if you type npm install and the folder contains a package.

Does Babel run before webpack?

js and . jsx files, we tell Webpack to use babel-loader which makes Webpack run these files through Babel before bundling them.


1 Answers

With the latest release of Snowpack (formerly @pika/web) this should be possible now!

From their website:

TL;DR - With Snowpack you can build modern web apps (using React, Vue, etc.) without a bundler (like Webpack, Parcel, Rollup). No more waiting for your bundler to rebuild your site every time you hit save. Instead, every change is reflected in the browser instantly.

And their "How it Works":

  1. Instead of bundling on every change, just run Snowpack once right after npm install.
  2. Snowpack re-installs your dependencies as single JS files to a new web_modules/ directory. It never touches your source code.
  3. Write code, import those dependencies via an ESM import, and then run it all in the browser.
  4. Skip the bundle step and see your changes reflected in the browser immediately after hitting save.
  5. Keep using your favorite web frameworks and build tools! Babel & TypeScript supported.

check https://www.snowpack.dev/ for more information, they have done a great job with their documentation, it looks really promising!

like image 167
Putzi San Avatar answered Oct 27 '22 01:10

Putzi San