Skip to content

Commit

Permalink
feat(webpack-runner): h5环境支持自定义source-map格式 (#4722)
Browse files Browse the repository at this point in the history
  • Loading branch information
Liaozzzzzz authored and Littly committed Nov 26, 2019
1 parent de11450 commit 472324d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
3 changes: 3 additions & 0 deletions docs/config-detail.md
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,9 @@ Taro app 的入口,同 [webpack.entry](https://webpack.js.org/configuration/en
sourceMap 开关,影响 js、css 的 sourceMap 配置。
dev 状态默认 ****,prod 状态默认 ****

### h5.sourceMapType
sourceMap格式, 默认cheap-module-eval-source-map。[具体配置](https://webpack.js.org/configuration/devtool/#devtool)

### h5.enableDll

dll 开关,开启后将使用 `dllPlugin` 把内置的部分依赖库打包为单独的 dll 文件,
Expand Down
11 changes: 6 additions & 5 deletions packages/taro-webpack-runner/src/config/dev.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ export default function (appPath: string, config: Partial<BuildConfig>): any {
designWidth = 750,
deviceRatio,
enableSourceMap = true,
sourceMapType,
enableExtract = false,

defineConstants = emptyObj,
env = emptyObj,
styleLoaderOption = emptyObj,
Expand All @@ -47,7 +48,7 @@ export default function (appPath: string, config: Partial<BuildConfig>): any {
mediaUrlLoaderOption = emptyObj,
fontUrlLoaderOption = emptyObj,
imageUrlLoaderOption = emptyObj,

miniCssExtractPluginOption = emptyObj,
esnextModules = [],

Expand Down Expand Up @@ -93,7 +94,7 @@ export default function (appPath: string, config: Partial<BuildConfig>): any {

chain.merge({
mode,
devtool: getDevtool([enableSourceMap]),
devtool: getDevtool({ enableSourceMap, sourceMapType }),
entry,
output: getOutput(appPath, [{
outputRoot,
Expand All @@ -106,7 +107,7 @@ export default function (appPath: string, config: Partial<BuildConfig>): any {
deviceRatio,
enableExtract,
enableSourceMap,

styleLoaderOption,
cssLoaderOption,
lessLoaderOption,
Expand All @@ -116,7 +117,7 @@ export default function (appPath: string, config: Partial<BuildConfig>): any {
imageUrlLoaderOption,
mediaUrlLoaderOption,
esnextModules,

module,
plugins,
staticDirectory
Expand Down
7 changes: 4 additions & 3 deletions packages/taro-webpack-runner/src/config/prod.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default function (appPath: string, config: Partial<BuildConfig>): any {
designWidth = 750,
deviceRatio,
enableSourceMap = false,
sourceMapType,
enableExtract = true,

defineConstants = emptyObj,
Expand Down Expand Up @@ -114,7 +115,7 @@ export default function (appPath: string, config: Partial<BuildConfig>): any {

chain.merge({
mode,
devtool: getDevtool(enableSourceMap),
devtool: getDevtool({ enableSourceMap, sourceMapType }),
entry,
output: getOutput(appPath, [{
outputRoot,
Expand All @@ -127,7 +128,7 @@ export default function (appPath: string, config: Partial<BuildConfig>): any {
deviceRatio,
enableExtract,
enableSourceMap,

styleLoaderOption,
cssLoaderOption,
lessLoaderOption,
Expand All @@ -137,7 +138,7 @@ export default function (appPath: string, config: Partial<BuildConfig>): any {
imageUrlLoaderOption,
mediaUrlLoaderOption,
esnextModules,

module,
plugins,
staticDirectory
Expand Down
4 changes: 2 additions & 2 deletions packages/taro-webpack-runner/src/util/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,8 @@ const getOutput = (appPath: string, [{ outputRoot, publicPath, chunkDirectory },
}
}

const getDevtool = enableSourceMap => {
return enableSourceMap ? 'cheap-module-eval-source-map' : 'none'
const getDevtool = ({ enableSourceMap, sourceMapType }) => {
return enableSourceMap ? sourceMapType || 'cheap-module-eval-source-map' : 'none'
}

export {
Expand Down
1 change: 1 addition & 0 deletions packages/taro-webpack-runner/src/util/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export interface TaroH5Config {
router?: IH5RouterConfig;
devServer: webpackDevServer.Configuration;
enableSourceMap: boolean;
sourceMapType?: 'none' | 'eval' | 'cheap-eval-source-map' | 'cheap-module-eval-source-map' | 'eval-source-map' | 'cheap-source-map' | 'cheap-module-source-map' | 'inline-cheap-source-map' | 'inline-cheap-module-source-map' | 'source-map' | 'inline-source-map' | 'hidden-source-map' | 'nosources-source-map';
enableExtract: boolean;

cssLoaderOption: Option;
Expand Down

0 comments on commit 472324d

Please sign in to comment.