-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into feat-bind-this
# Conflicts: # docs-vuepress/api/compile.md
- Loading branch information
Showing
104 changed files
with
1,739 additions
and
1,478 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
name: test | ||
|
||
on: [push] | ||
on: [push, pull_request] | ||
|
||
jobs: | ||
lint: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -250,6 +250,7 @@ module.exports = defineConfig({ | |
}) | ||
``` | ||
::: | ||
|
||
### externalClasses | ||
|
||
- **类型**:`Array<string>` | ||
|
@@ -488,6 +489,7 @@ module.exports = defineConfig({ | |
}) | ||
``` | ||
::: | ||
|
||
### autoSplit | ||
|
||
- **类型**:`boolean` | ||
|
@@ -1126,8 +1128,6 @@ module.exports = defineConfig({ | |
``` | ||
::: | ||
### i18n | ||
```js | ||
|
@@ -1432,135 +1432,161 @@ new MpxWebpackPlugin({ | |
}) | ||
``` | ||
### asyncSubpackageRules | ||
## MpxWebpackPlugin static methods | ||
- **类型**: | ||
```ts | ||
type Condition = string | Function | RegExp | ||
|
||
`MpxWebpackPlugin` 通过静态方法暴露了以下五个内置 loader,详情如下: | ||
interface AsyncSubpackageRules { | ||
include: Condition | Array<Condition> | ||
exclude?: Condition | Array<Condition> | ||
root: string | ||
placeholder: string | { name: string, resource?: string} | ||
} | ||
``` | ||
* include: 同 webpack include 规则 | ||
* exclude: 同 webpack exclude 规则 | ||
* root: 匹配规则的组件或js模块的输出分包名 | ||
* placeholder: 匹配规则的组件所配置的componentPlaceholder,可支持配置原生组件和自定义组件,原生组件可直接以string类型配置,自定义组件需要配置对象,name 为该自定义组件名, resource 为自定义组件的路径,路径可为绝对路径和相对于项目目录的相对路径 | ||
### MpxWebpackPlugin.loader | ||
- **详细**:异步分包场景下批量设置组件或 js 模块的异步分包,提升资源异步分包输出的灵活性。 | ||
`MpxWebpackPlugin` 所提供的最主要 loader,用于处理 `.mpx` 文件,根据不同的[模式(mode)](/api/compile.html#mode)将 `.mpx` 文件输出为不同的结果。 | ||
- **示例**: | ||
> \* 在微信环境下 `todo.mpx` 被loader处理后的文件为:`todo.wxml`、`todo.wxss`、`todo.js`、`todo.json` | ||
```js | ||
// include 可以是正则、字符串、函数、数组 | ||
new MpxWebpackPlugin({ | ||
asyncSubpackageRules: [ | ||
{ | ||
include: '/project/pages', // 文件路径包含 '/project/pages' 的组件或者 require.async 异步引用的js 模块都会被打包至sub1分包 | ||
root: 'sub1', | ||
placeholder: 'view' | ||
} | ||
] | ||
}) | ||
// 若配置自定义组件 | ||
new MpxWebpackPlugin({ | ||
asyncSubpackageRules: [ | ||
{ | ||
include: '/project/pages', // 文件路径包含 '/project/pages' 的组件或者 require.async 异步引用的js 模块都会被打包至sub1分包 | ||
root: 'sub1', | ||
placeholder: { | ||
name: 'other-placeholder', | ||
resource: '/user/xxxx/other.mpx' // 自定义组件的绝对路径 | ||
} | ||
} | ||
] | ||
}) | ||
``` | ||
::: tip @mpxjs/[email protected] 版本配置如下 | ||
```js | ||
module.exports = { | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.mpx$/, | ||
use: MpxWebpackPlugin.loader(options) | ||
// vue.config.js | ||
module.exports = defineConfig({ | ||
pluginOptions: { | ||
mpx: { | ||
plugin: { | ||
// include 可以是正则、字符串、函数、数组 | ||
asyncSubpackageRules: [ | ||
{ | ||
include: '/project/pages', // 文件路径包含 '/project/pages' 的组件或者 require.async 异步引用的js 模块都会被打包至sub1分包 | ||
root: 'sub1', | ||
placeholder: 'view' | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
}; | ||
}) | ||
``` | ||
::: | ||
#### Options | ||
:::warning | ||
* 该配置匹配的组件,若使用方在引用路径已设置?root或componentPlaceholder,则以引用路径中的?root或componentPlaceholder为最高优先级 | ||
* 若placeholder配置使用自定义组件,注意一定要配置 placeholder 中的 resource 字段 | ||
* 本功能只会对使用require.async异步引用的js模块生效,若引用路径中已配置?root,则以路径中?root优先 | ||
::: | ||
##### Options.transRpx `{Array<Object> | Object}` | ||
### retryRequireAsync | ||
用于统一转换 px 或者 rpx 单位,默认值为`{}`,详见 [transRpxRules](/api/compile.html#transrpxrules) | ||
`boolean = false` | ||
:::warning | ||
`transRpx` 已在`v2.6.0`版本中**移除**,请在统一配置文件 `build/mpx.plugin.conf.js` 中使用 `transRpxRules` 属性进行配置。 | ||
::: | ||
开启时在处理`require.async`时会添加单次重试逻辑 | ||
::: tip @mpxjs/[email protected] 版本配置如下 | ||
```javascript | ||
```js | ||
// vue.config.js | ||
module.exports = defineConfig({ | ||
pluginOptions: { | ||
mpx: { | ||
loader: { | ||
transRpxRules: [] | ||
plugin: { | ||
retryRequireAsync: true | ||
} | ||
} | ||
} | ||
}) | ||
``` | ||
::: | ||
##### Options.loaders `{Object}` | ||
### enableAliRequireAsync | ||
`boolean = false` | ||
可用于对某些资源文件的默认 loader 做覆盖或新增处理,以下例子演示了对 [less-loader](https://webpack.docschina.org/loaders/less-loader/) 做额外配置。 | ||
支付宝在`2.8.2`基础库版本后开始支持分包异步化,开启此配置时Mpx的分包异步构建能力能在输出支付宝时生效,不开启时则还是采用兜底策略进行构建来兼容`2.8.2`之前的基础库版本 | ||
```js | ||
module.exports = { | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.mpx$/, | ||
use: MpxWebpackPlugin.loader({ | ||
loaders: { // loaders选项 | ||
less: [ // 针对less做loader配置 | ||
'css-loader', | ||
{ | ||
loader: 'less-loader', | ||
options: { // 为less-loader添加额外配置 | ||
lessOptions: { | ||
strictMath: true | ||
} | ||
} | ||
} | ||
] | ||
} | ||
}) | ||
// vue.config.js | ||
module.exports = defineConfig({ | ||
pluginOptions: { | ||
mpx: { | ||
plugin: { | ||
enableAliRequireAsync: true | ||
} | ||
] | ||
} | ||
} | ||
}; | ||
}) | ||
``` | ||
::: tip @mpxjs/cli 3.x 版本配置如下 | ||
### optimizeSize | ||
`boolean = false` | ||
开启后可优化编译配置减少构建产物体积 | ||
```js | ||
const { defineConfig } = require('@vue/cli-service') | ||
// vue.config.js | ||
module.exports = defineConfig({ | ||
pluginOptions: { | ||
mpx: { | ||
loader: { | ||
loaders: { // loaders选项 | ||
less: [ // 针对less做loader配置 | ||
'css-loader', | ||
{ | ||
loader: 'less-loader', | ||
options: { // 为less-loader添加额外配置 | ||
lessOptions: { | ||
strictMath: true | ||
} | ||
} | ||
} | ||
] | ||
} | ||
plugin: { | ||
optimizeSize: true | ||
} | ||
} | ||
} | ||
}) | ||
``` | ||
::: | ||
##### Options.templateOption `{Object}` | ||
针对使用其他模板引擎(如 [pug](https://www.pugjs.cn/api/getting-started.html))来编写 template 的情景下,可通过 `options.templateOption` 来传入引擎渲染时的额外参数。等同于: | ||
## MpxWebpackPlugin static methods | ||
```js | ||
const pug = require('pug') | ||
`MpxWebpackPlugin` 通过静态方法暴露了以下五个内置 loader,详情如下: | ||
const template = `view(class='gray') 这是一段pug模板` | ||
### MpxWebpackPlugin.loader | ||
pug.render(template, options.templateOption) | ||
``` | ||
`MpxWebpackPlugin` 所提供的最主要 loader,用于处理 `.mpx` 文件,根据不同的[目标平台](#mode)将 `.mpx` 文件输出为不同的结果。 | ||
::: tip | ||
在 `@mpxjs/cli 3.x`版本已经内置了对于 `pug` 的支持,只需要安装 `pug` 依赖相关即可: | ||
> 在微信环境下 `todo.mpx` 被loader处理后的文件为:`todo.wxml`、`todo.wxss`、`todo.js`、`todo.json` | ||
```javascript | ||
npm install -D pug pug-plain-loader | ||
```js | ||
module.exports = { | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.mpx$/, | ||
use: MpxWebpackPlugin.loader() | ||
} | ||
] | ||
} | ||
}; | ||
``` | ||
::: | ||
##### Options.excludedPreLoaders `{RegExp}` | ||
在构建过程中忽略特定 `pre-loader` 对文件的处理,仅支持正则表达式,默认值为 `/eslint-loader/`。 | ||
### MpxWebpackPlugin.pluginLoader | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ | |
"packages": [ | ||
"packages/*" | ||
], | ||
"version": "2.8.29" | ||
"version": "2.8.49" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.