mirror of
https://github.com/aelve/guide.git
synced 2024-12-23 21:02:13 +03:00
Extract express config #167
This commit is contained in:
parent
b836a16b05
commit
10e31a82ea
38
front-ps/server.js
Normal file
38
front-ps/server.js
Normal file
@ -0,0 +1,38 @@
|
||||
var path = require('path');
|
||||
const spawn = require('child_process').spawn
|
||||
var webpack = require('webpack');
|
||||
var express = require('express');
|
||||
var config = require('./webpack.config.client');
|
||||
|
||||
const port = 8080;
|
||||
const compiler = webpack(require('./webpack.config.server.js'))
|
||||
const client = webpack(config);
|
||||
let server = null;
|
||||
const app = require('express')();
|
||||
app.use(function(req, res, next) {
|
||||
res.header("Access-Control-Allow-Origin", "*");
|
||||
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
||||
next();
|
||||
});
|
||||
app.use(require('webpack-dev-middleware')(client, {
|
||||
noInfo: true,
|
||||
publicPath: config.output.publicPath
|
||||
}));
|
||||
app.use(require('webpack-hot-middleware')(client));
|
||||
app.listen(8080);
|
||||
|
||||
console.log('Compiling...')
|
||||
|
||||
compiler.watch({
|
||||
aggregateTimeout: 300,
|
||||
poll: undefined
|
||||
}, (err, stats) => {
|
||||
if (err) return console.error(err)
|
||||
|
||||
if (server && !stats.hasErrors()) {
|
||||
server.kill('SIGKILL')
|
||||
server = spawn('node', ['./dist/server.js']);
|
||||
} else {
|
||||
server = spawn('node', ['./dist/server.js']);
|
||||
}
|
||||
})
|
@ -23,7 +23,7 @@ if (isProd) {
|
||||
})
|
||||
)
|
||||
} else {
|
||||
entries.unshift('webpack-hot-middleware/client?path=http://localhost:8080/__webpack_hmr&reload=true');
|
||||
entries.unshift(`webpack-hot-middleware/client?path=http://localhost:8080/__webpack_hmr&reload=true`);
|
||||
plugins.push(
|
||||
new webpack.HotModuleReplacementPlugin(),
|
||||
new webpack.NoEmitOnErrorsPlugin()
|
||||
@ -87,41 +87,4 @@ const config = {
|
||||
chunkModules: false
|
||||
}
|
||||
}
|
||||
|
||||
// If this file is directly run with node, start the development server
|
||||
// instead of exporting the webpack config.
|
||||
if (require.main === module) {
|
||||
const compiler = webpack(require('./webpack.config.server.js'))
|
||||
const client = webpack(config);
|
||||
let server = null;
|
||||
const app = require('express')();
|
||||
app.use(function(req, res, next) {
|
||||
res.header("Access-Control-Allow-Origin", "*");
|
||||
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
||||
next();
|
||||
});
|
||||
app.use(require('webpack-dev-middleware')(client, {
|
||||
noInfo: true,
|
||||
publicPath: config.output.publicPath
|
||||
}));
|
||||
app.use(require('webpack-hot-middleware')(client));
|
||||
app.listen(8080);
|
||||
|
||||
console.log('Compiling...')
|
||||
|
||||
compiler.watch({
|
||||
aggregateTimeout: 300,
|
||||
poll: undefined
|
||||
}, (err, stats) => {
|
||||
if (err) return console.error(err)
|
||||
|
||||
if (server && !stats.hasErrors()) {
|
||||
server.kill('SIGKILL')
|
||||
server = spawn('node', ['./dist/server.js']);
|
||||
} else {
|
||||
server = spawn('node', ['./dist/server.js']);
|
||||
}
|
||||
})
|
||||
} else {
|
||||
module.exports = config
|
||||
}
|
||||
module.exports = config
|
||||
|
Loading…
Reference in New Issue
Block a user