Skip to content

Commit

Permalink
feat: add midway-react-ssr
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyuang committed Jan 19, 2021
1 parent 07e2754 commit f5fe586
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
7 changes: 4 additions & 3 deletions packages/cli/src/cli.ts
Expand Up @@ -3,9 +3,7 @@ import { fork } from 'child_process'
import { resolve } from 'path'
import * as yargs from 'yargs'
import { Argv } from 'ssr-types'
import { parseFeRoutes, processError, checkDependencies } from 'ssr-server-utils'

checkDependencies()
const spinnerProcess = fork(resolve(__dirname, './spinner')) // 单独创建子进程跑 spinner 否则会被后续的 require 占用进程导致 loading 暂停

try {
Expand All @@ -15,6 +13,7 @@ try {
message: 'start'
})
process.env.NODE_ENV = 'development'
const { parseFeRoutes } = require('ssr-server-utils') // 延迟 require 防止 process.env.NODE_ENV 设置未生效
await parseFeRoutes()
const { start } = require('./start')
spinnerProcess.send({
Expand All @@ -28,6 +27,7 @@ try {
})
process.env.NODE_ENV = 'production'
const { build } = require('./build')
const { parseFeRoutes } = require('ssr-server-utils')
await parseFeRoutes()
spinnerProcess.send({
message: 'stop'
Expand All @@ -45,5 +45,6 @@ try {
})
.parse()
} catch (error) {
processError(error)
console.log(error)
process.exit(1)
}
5 changes: 1 addition & 4 deletions packages/webpack/src/config/server.ts
Expand Up @@ -6,7 +6,6 @@ import { nodeExternals } from '../plugins/external'

const { isDev, cwd, getOutput, chainServerConfig, whiteList } = buildConfig
const loadModule = require.resolve
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin

const getServerWebpack = () => {
const config = getBaseConfig()
Expand Down Expand Up @@ -65,9 +64,7 @@ const getServerWebpack = () => {
config.when(isDev, () => {
config.watch(true)
})
config.when(true, config => {
config.plugin('analyze').use(BundleAnalyzerPlugin)
})

config.plugin('define').use(webpack.DefinePlugin, [{
__isBrowser__: false
}])
Expand Down

0 comments on commit f5fe586

Please sign in to comment.