index.ts 980 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
import webpack from 'webpack'
import { base } from './blocks/base'
import { css } from './blocks/css'
import { ConfigurationContext, pipe } from './utils'

export async function build(
  config: webpack.Configuration,
  {
    rootDirectory,
    customAppFile,
    isDevelopment,
    isServer,
    hasSupportCss,
14
    hasSupportScss,
15
    assetPrefix,
16 17 18 19 20 21
  }: {
    rootDirectory: string
    customAppFile: string | null
    isDevelopment: boolean
    isServer: boolean
    hasSupportCss: boolean
22
    hasSupportScss: boolean
23
    assetPrefix: string
24 25 26 27 28 29 30 31 32
  }
): Promise<webpack.Configuration> {
  const ctx: ConfigurationContext = {
    rootDirectory,
    customAppFile,
    isDevelopment,
    isProduction: !isDevelopment,
    isServer,
    isClient: !isServer,
33 34 35 36 37
    assetPrefix: assetPrefix
      ? assetPrefix.endsWith('/')
        ? assetPrefix.slice(0, -1)
        : assetPrefix
      : '',
38 39
  }

40
  const fn = pipe(base(ctx), css(hasSupportCss, hasSupportScss, ctx))
41 42
  return fn(config)
}