2018-07-27 03:48:21 +00:00
|
|
|
'use strict';
|
|
|
|
// https://github.com/webpack/webpack-dev-server/blob/master/examples/api/simple/server.js
|
2023-09-04 01:50:14 +00:00
|
|
|
const dotenv = require('dotenv');
|
|
|
|
|
|
|
|
dotenv.config();
|
2018-07-27 03:48:21 +00:00
|
|
|
|
2020-12-15 10:00:39 +00:00
|
|
|
process.env.NODE_ENV = 'development';
|
|
|
|
process.env.BABEL_ENV = 'development';
|
|
|
|
|
2023-09-04 01:50:14 +00:00
|
|
|
const Webpack = require('webpack')
|
|
|
|
const WebpackDevServer = require('webpack-dev-server')
|
|
|
|
const ignoredFiles = require('react-dev-utils/ignoredFiles');
|
|
|
|
const configFactory = require('./webpack.config')
|
|
|
|
const paths = require('./paths');
|
|
|
|
const getHttpsConfig = require('./getHttpsConfig');
|
2018-07-27 03:48:21 +00:00
|
|
|
|
2023-09-04 01:50:14 +00:00
|
|
|
const HOST = process.env.HOST || '0.0.0.0';
|
|
|
|
const PORT = process.env.PORT || '3000';
|
|
|
|
const publicPath = process.env.PUBLIC_PATH || '/assets/bundles/';
|
|
|
|
|
|
|
|
const devServerOptions = {
|
|
|
|
allowedHosts: 'all',
|
2021-03-15 09:01:54 +00:00
|
|
|
hot: true,
|
2023-09-04 01:50:14 +00:00
|
|
|
static: {
|
|
|
|
directory: paths.appBuild,
|
|
|
|
publicPath: publicPath,
|
|
|
|
watch: {
|
|
|
|
ignored: ignoredFiles(paths.appSrc),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
client: {
|
|
|
|
overlay: false,
|
|
|
|
},
|
|
|
|
headers: {
|
|
|
|
'Access-Control-Allow-Origin': '*',
|
|
|
|
'Access-Control-Allow-Methods': '*',
|
|
|
|
'Access-Control-Allow-Headers': '*',
|
|
|
|
},
|
|
|
|
// Enable gzip compression of generated files.
|
|
|
|
compress: true,
|
|
|
|
https: getHttpsConfig(),
|
|
|
|
host: HOST,
|
|
|
|
port: PORT,
|
|
|
|
};
|
2018-07-27 03:48:21 +00:00
|
|
|
|
|
|
|
console.log('Dev server options:', devServerOptions);
|
|
|
|
|
2023-09-04 01:50:14 +00:00
|
|
|
const config = configFactory('development');
|
|
|
|
const compiler = Webpack(config);
|
|
|
|
const server = new WebpackDevServer(devServerOptions, compiler);
|
2018-07-27 03:48:21 +00:00
|
|
|
|
2023-09-04 01:50:14 +00:00
|
|
|
server.startCallback(() => {
|
|
|
|
console.log(`Listening at http://${HOST}:${PORT}${publicPath}`);
|
|
|
|
});
|