Skip to content

Commit

Permalink
fix(cli): fix build error
Browse files Browse the repository at this point in the history
affects: @varlet/cli
  • Loading branch information
haoziqaq committed Jul 19, 2021
1 parent d60158a commit 27f1947
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 5 additions & 3 deletions packages/varlet-cli/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import logger from '../shared/logger'
import { buildMobileSiteRoutes, buildPcSiteRoutes } from '../compiler/compileRoutes'
import { getBuildConfig } from '../config/webpack.build.config'
import { ensureDirSync } from 'fs-extra'
import { SRC_DIR } from '../shared/constant'
import { SITE_MOBILE, SITE_PC, SRC_DIR } from '../shared/constant'
import { resolve } from 'path'

export async function build() {
ensureDirSync(SRC_DIR)

await Promise.all([buildMobileSiteRoutes(), buildPcSiteRoutes()])

const [mobileRouteId, pcRouteId] = await Promise.all([buildMobileSiteRoutes(), buildPcSiteRoutes()])
const config = getBuildConfig()
config.resolve.alias['@pc-routes'] = resolve(SITE_PC, `./${pcRouteId}.routes.ts`)
config.resolve.alias['@mobile-routes'] = resolve(SITE_MOBILE, `./${mobileRouteId}.routes.ts`)

webpack(config, (err, stats) => {
err && logger.error(err.toString())
Expand Down
10 changes: 4 additions & 6 deletions packages/varlet-cli/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,9 @@ import { ensureDirSync } from 'fs-extra'
import { resolve } from 'path'
import { SRC_DIR, SITE_PC, SITE_MOBILE } from '../shared/constant'

let mobileRouteId: string
let pcRouteId: string

export function runDevServer(port: number, config: any) {
const { host } = config.devServer
config.devServer.port = port
config.resolve.alias['@pc-routes'] = resolve(SITE_PC, `./${pcRouteId}.routes.ts`)
config.resolve.alias['@mobile-routes'] = resolve(SITE_MOBILE, `./${mobileRouteId}.routes.ts`)
const server = new WebpackDevServer(webpack(config), config.devServer)

;(server as any).showStatus = function () {}
Expand All @@ -32,9 +27,12 @@ export function runDevServer(port: number, config: any) {

export async function dev() {
ensureDirSync(SRC_DIR)
;[mobileRouteId, pcRouteId] = await Promise.all([buildMobileSiteRoutes(), buildPcSiteRoutes()])

const [mobileRouteId, pcRouteId] = await Promise.all([buildMobileSiteRoutes(), buildPcSiteRoutes()])
const config = getDevConfig()
config.resolve.alias['@pc-routes'] = resolve(SITE_PC, `./${pcRouteId}.routes.ts`)
config.resolve.alias['@mobile-routes'] = resolve(SITE_MOBILE, `./${mobileRouteId}.routes.ts`)

const { port } = config.devServer
getPort(
{
Expand Down
2 changes: 1 addition & 1 deletion packages/varlet-cli/src/config/webpack.build.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import merge from 'webpack-merge'
import WebpackBarPlugin from 'webpackbar'
import CopyWebpackPlugin from 'copy-webpack-plugin'
import { BASE_CONFIG } from './webpack.base.config'
import { SITE_OUTPUT_PATH, PRIMARY_COLOR, SITE_PUBLIC_PATH } from '../shared/constant'
import { CleanWebpackPlugin } from 'clean-webpack-plugin'
import CopyWebpackPlugin from 'copy-webpack-plugin'
import { HTML_WEBPACK_PLUGINS } from './webpack.dev.config'

export function getBuildConfig() {
Expand Down

0 comments on commit 27f1947

Please sign in to comment.