UNPKG

@procore/core-scripts

Version:

A CLI to enhance your development experience

77 lines 3.37 kB
"use strict"; 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], port: config.port, 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, server: config.protocol === 'https' ? 'https' : 'http', proxy: config.proxy, static: { directory: workspace.resolve('public'), publicPath: [config.publicPath], watch: { ignored: (0, ignoredFiles_1.default)(workspace.resolve('src')), }, }, setupMiddlewares: (middlewares, devServer) => { if (!devServer) { throw new Error('webpack-dev-server is not defined'); } const app = devServer.app; if (config.devServerOverride) { config.devServerOverride(app); } // Use the `unshift` method if you want to run a middleware before all other middlewares // or when you are migrating from the `onBeforeSetupMiddleware` option middlewares.unshift( // Keep `evalSourceMapMiddleware` // This lets us fetch source contents from webpack for the error overlay (0, evalSourceMapMiddleware_1.default)(devServer)); // Use the `push` method if you want to run a middleware after all other middlewares // or when you are migrating from the `onAfterSetupMiddleware` option middlewares.push( // 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 // https://github.com/facebook/create-react-app/issues/2272#issuecomment-302832432 (0, noopServiceWorkerMiddleware_1.default)(config.publicPath)); return middlewares; }, }; } //# sourceMappingURL=devServerConfig.js.map