0

I have configured webpack-dev-middleware with sails. The publicPath in webpack configuration is set to /static/. Webpack builds the bundle.js without errors, but it is not available at localhost:3000/static/bundle.js.

How do I inject the bundle? Is there anything specific I need to do for sails?

ankit_m
  • 417
  • 2
  • 5
  • 16

1 Answers1

0

You need to define publicPath in two locations: the Webpack configuration, but also the webpack-dev-middleware options.

For instance, this is what I use (on Express, so not entirely sure if it'll work exactly the same with Sails):

const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackConfig        = require('./webpack.dev');
const compiler             = require('webpack')(webpackConfig);

app.use(webpackDevMiddleware(compiler, {
  noInfo     : true,
  publicPath : webpackConfig.output.publicPath
}));

(I have a separate Webpack configuration file called webpack.dev.js)

As you can see, I just re-use the publicPath from the Webpack configuration for the middleware.

robertklep
  • 198,204
  • 35
  • 394
  • 381
  • I have the exact same setting. It doesn't seem to work for sails. – ankit_m Mar 03 '17 at 14:54
  • If Sails handles requests to `/static` itself, it may be interfering with the Webpack middleware. You could try to use a different `publicPath` for Webpack to see if that makes any difference. – robertklep Mar 03 '17 at 15:25