This repository has been archived by the owner on Jan 24, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(docz-core): a lot of bundler improvements
- Loading branch information
1 parent
c935af5
commit 0284f52
Showing
17 changed files
with
703 additions
and
621 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,34 @@ | ||
import * as fs from 'fs' | ||
import chalk from 'chalk' | ||
import logger from 'signale' | ||
import { Configuration as Config } from 'webpack' | ||
import WebpackDevServer from 'webpack-dev-server' | ||
import { Configuration as Config } from 'webpack' | ||
|
||
import * as paths from '../config/paths' | ||
import { devServerConfig } from './devserver' | ||
import { Config as Args } from '../config/argv' | ||
import { ServerHooks as Hooks } from '../lib/Bundler' | ||
import * as serverUtils from 'react-dev-utils/WebpackDevServerUtils' | ||
|
||
export const server = (args: Args) => async (config: Config, hooks: Hooks) => { | ||
const useYarn = fs.existsSync(paths.appYarnLock) | ||
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http' | ||
const appName = require(paths.appPackageJson).name | ||
const urls = serverUtils.prepareUrls(protocol, args.host, args.port) | ||
const serverConfig: any = devServerConfig(hooks, args) | ||
|
||
const compiler = serverUtils.createCompiler( | ||
require('webpack'), | ||
config, | ||
appName, | ||
urls, | ||
useYarn | ||
) | ||
const createCompiler = (config: Config) => | ||
new Promise<any>(resolve => { | ||
try { | ||
resolve(require('webpack')(config)) | ||
} catch (err) { | ||
logger.fatal(chalk.red('Failed to compile.')) | ||
logger.fatal() | ||
logger.fatal(err.message || err) | ||
logger.fatal() | ||
process.exit(1) | ||
} | ||
}) | ||
|
||
return { | ||
start: async () => { | ||
const devServer = new WebpackDevServer(compiler, serverConfig) | ||
export const server = (args: Args) => async (config: Config, hooks: Hooks) => ({ | ||
start: async () => { | ||
const serverConfig: any = devServerConfig(hooks, args) | ||
const compiler = await createCompiler(config) | ||
const devServer = new WebpackDevServer(compiler, serverConfig) | ||
|
||
return devServer.listen(args.port, args.host, err => { | ||
if (err) return logger.fatal(err) | ||
hooks.onServerListening<WebpackDevServer>(devServer) | ||
}) | ||
}, | ||
} | ||
} | ||
return devServer.listen(args.port, args.host, err => { | ||
if (err) return logger.fatal(err) | ||
hooks.onServerListening<WebpackDevServer>(devServer) | ||
}) | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.