Skip to content

Commit

Permalink
fix(runner): 修复自定义环境变量导致的 mode 错误 fix #12436
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakaryCode committed Sep 21, 2022
1 parent 99d3af2 commit 60cefa8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
10 changes: 4 additions & 6 deletions packages/taro-webpack5-runner/src/utils/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { IH5Config, IMiniAppConfig, IProjectBaseConfig } from '@tarojs/taro/types/compile'

import { PrerenderConfig } from '../prerender/prerender'

import type { RecursiveTemplate, UnRecursiveTemplate } from '@tarojs/shared/dist/template'
import type { IH5Config, IMiniAppConfig, IProjectBaseConfig } from '@tarojs/taro/types/compile'
import type Webpack from 'webpack'
import type Chain from 'webpack-chain'
import type { PrerenderConfig } from '../prerender/prerender'
import type { IComponentConfig } from '../template/component'

export interface IOption {
Expand Down Expand Up @@ -45,7 +43,7 @@ export interface HookModifyWebpackChain {

export interface CommonBuildConfig extends IProjectBaseConfig {
entry?: Webpack.EntryObject
mode: 'production' | 'development'
mode: 'production' | 'development' | 'none'
}

export interface MiniBuildConfig extends CommonBuildConfig, IMiniAppConfig {
Expand Down Expand Up @@ -73,4 +71,4 @@ export interface H5BuildConfig extends CommonBuildConfig, IH5Config {
entryFileName?: string
}

export type AddPageChunks = ((pages: Map<string, string[]>, pagesNames?: string[]) => void)
export type AddPageChunks = (pages: Map<string, string[]>, pagesNames?: string[]) => void
9 changes: 6 additions & 3 deletions packages/taro-webpack5-runner/src/webpack/Combination.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { META_TYPE, recursiveMerge, SCRIPT_EXT } from '@tarojs/helper'
import { getSassLoaderOption } from '@tarojs/runner-utils'
import { isFunction, isObject } from '@tarojs/shared'
import { IPrebundle } from '@tarojs/webpack5-prebundle'
import path from 'path'
import webpack from 'webpack'
import Chain from 'webpack-chain'

import { componentConfig } from '../template/component'

import type { IPrebundle } from '@tarojs/webpack5-prebundle'
import type Chain from 'webpack-chain'
import type { CommonBuildConfig, H5BuildConfig, MiniBuildConfig } from '../utils/types'

type ICompiler = Exclude<CommonBuildConfig['compiler'], string | undefined>
Expand Down Expand Up @@ -44,12 +44,15 @@ export class Combination<T extends MiniBuildConfig | H5BuildConfig = CommonBuild
process (_config: T, _appPath: string) {}

async pre (rawConfig: T) {
const preMode = rawConfig.mode || process.env.NODE_ENV
const mode = ['production', 'development', 'none'].find(e => e === preMode)
|| (process.env.NODE_ENV === 'production' ? 'production' : 'development')
/** process config.sass options */
const sassLoaderOption = await getSassLoaderOption(rawConfig)
this.config = {
...rawConfig,
sassLoaderOption,
mode: process.env.NODE_ENV || rawConfig.mode,
mode,
frameworkExts: rawConfig.frameworkExts || SCRIPT_EXT
}
}
Expand Down

0 comments on commit 60cefa8

Please sign in to comment.