mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2025-02-17 00:21:20 -05:00
Use webpack-dev-middleware for assets in dev
This commit is contained in:
parent
c065df3faa
commit
ae8d4d8990
2 changed files with 18 additions and 4 deletions
|
@ -70,6 +70,7 @@
|
|||
"url-loader": "0.5.6",
|
||||
"watch": "0.16.0",
|
||||
"webpack": "1.12.2",
|
||||
"webpack-dev-middleware": "1.2.0",
|
||||
"xhr": "2.0.4"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@ var express = require('express');
|
|||
var path = require('path');
|
||||
var proxy = require('express-http-proxy');
|
||||
var url = require('url');
|
||||
var webpackDevMiddleware = require('webpack-dev-middleware');
|
||||
var webpack = require('webpack');
|
||||
|
||||
var handler = require('./handler');
|
||||
var log = require('./log');
|
||||
|
@ -34,10 +36,12 @@ if (isProduction) {
|
|||
// Server setup
|
||||
app.use(log());
|
||||
app.use(compression());
|
||||
app.use(express.static(path.resolve(__dirname, '../build'), {
|
||||
lastModified: true,
|
||||
maxAge: '1y'
|
||||
}));
|
||||
if (isProduction) {
|
||||
app.use(express.static(path.resolve(__dirname, '../build'), {
|
||||
lastModified: true,
|
||||
maxAge: '1y'
|
||||
}));
|
||||
}
|
||||
app.use(function (req, res, next) {
|
||||
req._path = url.parse(req.url).path;
|
||||
next();
|
||||
|
@ -82,6 +86,15 @@ if (!isProduction) {
|
|||
return req._path;
|
||||
}
|
||||
}));
|
||||
|
||||
// Use webpack-dev-server in development
|
||||
var compiler = webpack(require('../webpack.config.js'));
|
||||
app.use(webpackDevMiddleware(compiler, {
|
||||
headers: {
|
||||
'X-From-Webpack': true
|
||||
}
|
||||
}));
|
||||
|
||||
}
|
||||
|
||||
// Start listening
|
||||
|
|
Loading…
Reference in a new issue