@procore/core-scripts
Version:
A CLI to enhance your development experience
71 lines • 2.98 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.devServerConfigFactory = devServerConfigFactory;
const tslib_1 = require("tslib");
const evalSourceMapMiddleware_1 = tslib_1.__importDefault(require("react-dev-utils/evalSourceMapMiddleware"));
const ignoredFiles_1 = tslib_1.__importDefault(require("react-dev-utils/ignoredFiles"));
const noopServiceWorkerMiddleware_1 = tslib_1.__importDefault(require("react-dev-utils/noopServiceWorkerMiddleware"));
const url_1 = tslib_1.__importDefault(require("url"));
function devServerConfigFactory(workspace, config) {
const allowedHost = url_1.default.format({
hostname: config.allowedHost,
port: config.port,
protocol: config.protocol,
});
const disableFirewall = !config.proxy || config.dangerouslyDisableHostCheck;
return {
allowedHosts: disableFirewall ? 'all' : [allowedHost],
client: {
logging: 'none',
overlay: {
errors: true,
warnings: false,
},
webSocketURL: {
hostname: config.sockHost,
},
},
compress: true,
devMiddleware: {
publicPath: config.publicPath,
},
headers: {
'Access-Control-Allow-Origin': '*',
},
historyApiFallback: {
// See https://github.com/facebook/create-react-app/issues/387.
disableDotRule: true,
index: config.publicPath,
},
host: config.host,
https: config.protocol === 'https',
proxy: config.proxy,
static: {
directory: workspace.resolve('public'),
publicPath: [config.publicPath],
watch: {
ignored: (0, ignoredFiles_1.default)(workspace.resolve('src')),
},
},
onBeforeSetupMiddleware(devServer) {
const app = devServer.app;
if (config.devServerOverride) {
config.devServerOverride(app);
}
// Keep `evalSourceMapMiddleware`
// middlewares before `redirectServedPath` otherwise will not have any effect
// This lets us fetch source contents from webpack for the error overlay
app.use((0, evalSourceMapMiddleware_1.default)(devServer));
},
onAfterSetupMiddleware(devServer) {
const app = devServer.app;
// This service worker file is effectively a 'no-op' that will reset any
// previous service worker registered for the same host:port combination.
// We do this in development to avoid hitting the production cache if
// it used the same host and port.
// https://github.com/facebook/create-react-app/issues/2272#issuecomment-302832432
app.use((0, noopServiceWorkerMiddleware_1.default)(config.publicPath));
},
};
}
//# sourceMappingURL=devServerConfig.js.map