Skip to content

Commit

Permalink
fix(webpack-runner): 移除了webpack配置项,并补全文档
Browse files Browse the repository at this point in the history
  • Loading branch information
Littly committed Mar 15, 2019
1 parent 555e82d commit 5a90559
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
3 changes: 1 addition & 2 deletions packages/taro-webpack-runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@
"webpack": "4.14.0",
"webpack-chain": "4.9.0",
"webpack-dev-server": "3.1.14",
"webpack-format-messages": "2.0.3",
"webpack-merge": "4.1.4"
"webpack-format-messages": "2.0.3"
},
"devDependencies": {
"@types/autoprefixer": "6.7.3",
Expand Down
27 changes: 13 additions & 14 deletions packages/taro-webpack-runner/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import chalk from 'chalk'
import * as opn from 'opn'
import * as path from 'path'
import { format as formatUrl } from 'url'
import { deprecate } from 'util'
import * as webpack from 'webpack'
import * as WebpackDevServer from 'webpack-dev-server'
import * as webpackMerge from 'webpack-merge'

import buildConf from './config/build.conf'
import devConf from './config/dev.conf'
Expand All @@ -21,25 +19,22 @@ const customizeChain = (chain, customizeFunc: Function) => {
}
}

const deprecatedCustomizeConfig = deprecate((baseConfig, customConfig) => {
if (customConfig instanceof Function) {
return customConfig(baseConfig, webpack)
} else if (customConfig instanceof Object) {
return webpackMerge({}, baseConfig, customConfig)
}
}, chalk.yellow(`h5.webpack配置项即将停止支持,请尽快迁移到新配置项。新配置项文档:https://nervjs.github.io/taro/docs/config-detail.html#h5`))
const warnConfigWebpack = () => {
console.log(chalk.yellow(`taro@1.3版本开始,h5.webpack配置项已经停止支持。作为代替,请使用配置项h5.webpackChain,文档:https://nervjs.github.io/taro/docs/config-detail.html#h5webpackchain`))
}
const warnConfigEnableDll = () => {
console.log(chalk.yellow(`taro@1.3版本开始,taro在h5端加强了代码体积控制,抽离dll的收益已经微乎其微,同时也容易导致一些问题(#1800等)。所以h5.enableDll配置项暂时移除。`))
}

const buildProd = (config: BuildConfig): Promise<void> => {
return new Promise((resolve, reject) => {
const webpackChain = prodConf(config)
let webpackConfig
const webpackConfig = webpackChain.toConfig()

customizeChain(webpackChain, config.webpackChain)

if (config.webpack) {
webpackConfig = deprecatedCustomizeConfig(webpackChain.toConfig(), config.webpack)
} else {
webpackConfig = webpackChain.toConfig()
warnConfigWebpack()
}

const compiler = webpack(webpackConfig)
Expand Down Expand Up @@ -70,8 +65,9 @@ const buildDev = async (config: BuildConfig): Promise<any> => {
customizeChain(webpackChain, config.webpackChain)

webpackConfig = webpackChain.toConfig()

if (config.webpack) {
webpackConfig = deprecatedCustomizeConfig(webpackChain.toConfig(), config.webpack)
warnConfigWebpack()
}

const devServerOptions = recursiveMerge(
Expand Down Expand Up @@ -115,6 +111,9 @@ export default async (config: BuildConfig): Promise<void> => {
if (config.isWatch) {
await buildDev(config)
} else {
if ('enableDll' in config) {
warnConfigEnableDll()
}
await buildProd(config)
}
}
1 change: 0 additions & 1 deletion packages/taro-webpack-runner/src/util/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export interface TaroH5Config {
webpack: ((webpackConfig: webpack.Configuration, webpack) => webpack.Configuration) | webpack.Configuration

webpackChain: (chain: any, webpack: any) => void;
dllWebpackChain: (chain: any, webpack: any) => void;

alias: Option;
entry: webpack.Entry;
Expand Down

0 comments on commit 5a90559

Please sign in to comment.