Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use webpack for development without webpack dev server?

I am currently using require.js for development so I can iterate quickly (change a file, refresh page, no build step in between), but I use webpack as a build tool since it is superior to r.js. I would like to get rid of require.js entirely and use webpack as a script loader in development. I know that's exactly what webpack dev server is for, but I specifically don't want to use it.

Ideally I would just include some kind of webpack loader in <script>, point it to my webpack.js build config, and let it do the job.

like image 655
Adam Zielinski Avatar asked Dec 17 '14 18:12

Adam Zielinski


People also ask

Why do we need Webpack dev server?

So that you don't have to spin up other servers like node to see your project locally, webpack dev server provides you a port number where you can see or test your project in the browser locally. When you run webpack dev server what webpack dev server does is, instead of creating a bundled file ( e.g. bundle.

How do I run a webpack locally?

To run the local installation of webpack you can access its binary version as node_modules/. bin/webpack . Alternatively, if you are using npm v5. 2.0 or greater, you can run npx webpack to do it.

Can webpack work without config?

Out of the box, webpack won't require you to use a configuration file. However, it will assume the entry point of your project is src/index.js and will output the result in dist/main.js minified and optimized for production.

Is webpack needed anymore?

The Ecosystem now The newer bundlers have simpler configuration, allowing people to add/create plugins and configure the setup more easily, and some utilize ESM to make ultra fast reload speeds and smaller bundles. Because of this, Webpack is not the best tool to use anymore.


1 Answers

If you don't want to use webpack-dev-server, you could use webpack's watch functionality to keep building your script as you make changes. That will give you the workflow you're looking for. In the index.html, you'll be including your bundle only and no loader.

http://webpack.github.io/docs/tutorials/getting-started/#watch-mode

like image 200
Jeff Ling Avatar answered Oct 07 '22 07:10

Jeff Ling