Skip to content
This repository has been archived by the owner on Jul 12, 2018. It is now read-only.

Use webpack-dev-middleware #11

Open
sokra opened this issue Sep 16, 2012 · 4 comments
Open

Use webpack-dev-middleware #11

sokra opened this issue Sep 16, 2012 · 4 comments
Assignees
Milestone

Comments

@sokra
Copy link

sokra commented Sep 16, 2012

Use the webpack-dev-middleware for serving a webpack bundle.

It may need some more refactoring...

Your current impl has some restrictions:

  • No code splitting, because you only serve one bundle file.
  • Resources emitted in webpack would not be served: require('file/png!./resource.png')
  • Recompilation on each request
  • Only stuff in the specified directory is watched. Check the `bundle-invalid' event emitted from webpack.
  • Changes in loaders are not handled correctly.
@topa
Copy link
Member

topa commented Sep 16, 2012

Merci for your suggestions. But some of the points you've mentioned are rather features than restrictions. Let's get through it point by point:

No code splitting, because you only serve one bundle file.

If there is only one file, than you only have to include this one file. nof5 serves the bundle as tests.js. You can see here an living example: https://github.com/peerigon/alamid/blob/master/test/client/index.html .
This is much simpler and more usable than including each test separately.
Additionally Chrome and Firefox are able to re-split this one file in more files with //@ sourceURL=". I think this also happens if debug: true is set in webpack's options.

Resources emitted in webpack would not be served: require('file/png!./resource.png')

I'm not sure if this will be a real use case for client side unit tests.

Recompilation on each request

If a change happened in the test or lib folder than this behavior is desired. But you're right if you say that not every test needs to be recompiled. On the other hand the recompilation of all tests is damn fast at the current state and no real issue.

Only stuff in the specified directory is watched. Check the `bundle-invalid' event emitted from webpack.

nof5 watches the given folder or process.cwd() and all it sub-folders and is also able to watch a lib folder. Besides you can define an additional folder for assets that files will be statically served. nof5's documentation is not finished at the moment, but you can take a look here for all options: https://github.com/peerigon/nof5/blob/master/lib/Config.js

Changes in loaders are not handled correctly.

I don't really understand the last point. @jhnns helped me with the loader implementation.

Thanks a lot for your pull request. I take a look at it.

@sokra
Copy link
Author

sokra commented Sep 16, 2012

I just want to say that you don't use webpack's full potential in some aspects. That's ok, but I've already have written a module which would care about above aspects. Webpack has watching integrated and there are already a middleware for express which cares about the im memory compliation and serving. You can use it, if you want to.

var options = {
  events: new EventEmitter(),
  output: "tests.js"
};
options.events.on("bundle-invalid", function() {
  // On file change, the bundle becomes invalid.
  // We need to update the page
  io.sockets.emit("f5");
});
// serve bundle and other emitted files
app.use(webpackDevMiddleware(testsLoader + "!" + testsLoader, options));

@ghost ghost assigned topa Sep 17, 2012
@topa
Copy link
Member

topa commented Sep 17, 2012

nof5 is written to support multiple bundlers like browserify and webpack. Maybe in future we'll decided to bake nof5 with webpack, like alamid. If so nof5 will surely make use of your suggested improvement here.

But as you already mentioned

It may need some more refactoring...

and at the moment nof5 is doing what it should to.

I marked this issue as enhancement and attached it to milestone 0.3.0, so that it will be discussed for further releases.

@sokra
Copy link
Author

sokra commented Sep 17, 2012

Yes it intended as (future) enhancement.

It not to complicated, but i think it do not fit easily into the nof5 architecture, so I implemented it standalone: webpack-dev-server ;)
Feel free to use some code, if you want to add it to nof5.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants