Skip to content

Commit

Permalink
fix(mini-runner): 修复 defineConstants 小程序表现与 H5 不一致问题 close #5078
Browse files Browse the repository at this point in the history
  • Loading branch information
Garfield550 authored and luckyadam committed Dec 31, 2019
1 parent 61ee57c commit a560edb
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 6 deletions.
4 changes: 2 additions & 2 deletions docs/config-detail.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,11 @@ env: {

## defineConstants

用来配置一些全局变量供代码中进行使用,例如:
用来配置一些全局变量供代码中进行使用,配置方式与 [Webpack DefinePlugin](https://webpack.js.org/plugins/define-plugin/) 类似,例如:

```js
defineConstants: {
A: '"a"' // JSON.stringify('a')
A: JSON.stringify('a') // '"a"'
}
```

Expand Down
1 change: 0 additions & 1 deletion packages/taro-mini-runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"babel-loader": "^8.0.6",
"babel-plugin-danger-remove-unused-import": "^1.1.2",
"babel-plugin-preval": "1.6.4",
"babel-plugin-transform-define": "^1.3.1",
"babel-traverse": "^6.26.0",
"babel-types": "^6.26.0",
"better-babel-generator": "^6.26.1",
Expand Down
4 changes: 1 addition & 3 deletions packages/taro-mini-runner/src/loaders/fileParseLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,6 @@ function processAst (
export default function fileParseLoader (source, ast) {
const {
babel: babelConfig,
constantsReplaceList,
buildAdapter,
designWidth,
deviceRatio,
Expand All @@ -514,8 +513,7 @@ export default function fileParseLoader (source, ast) {
const newAst = transformFromAst(ast, '', {
plugins: [
[require('babel-plugin-preval')],
[require('babel-plugin-danger-remove-unused-import'), { ignore: cannotRemoves }],
[require('babel-plugin-transform-define').default, constantsReplaceList]
[require('babel-plugin-danger-remove-unused-import'), { ignore: cannotRemoves }]
]
}).ast as t.File
const miniType = this._module.miniType || PARSE_AST_TYPE.NORMAL
Expand Down

0 comments on commit a560edb

Please sign in to comment.