Skip to content

add external option #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,30 @@ mpvueSimple.build() // => Promise
```

## changelog
#### `1.0.18`

- 加入可选配置项 `externals`,通过在webpack中增加external属性的方式,可以在打包的时候移除公共模块的引入,从而减小包大小。

在构建脚本中进行如下定义:

```javascript
mpvueSimple.build({
externals: {
sdk: 'require("../../../../sdk")', // 公共模块的相对路径
},
})
```

在页面文件中进行如下引用:

```javascript
import SDK from 'sdk'; // 注意这里的sdk,应为externals的key
```




#### `1.0.17`

- 加入可选配置项 `output.jsonpFunction`,mpvue 打包构建后会在 `manifest.js` 中生生成全局的模块加载器函数 `global.webpackJsonp`,为防止和其它构建工具引起命名冲突,该默认函数名可在 output 配置中指定,示例如上。

1 change: 1 addition & 0 deletions build/webpack.base.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module.exports = {
resolveLoader: {
modules
},
externals: config.build.externals,
module: {
rules: [
{
Expand Down
6 changes: 6 additions & 0 deletions config/argv.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ function mergeArgvConfig (config) {
output: argvOutput, // pathString, undefined
config: argvCnf, // pathString, undefined
definePlugin: argvDefinePlugin, // object, undefined
externals: argvExternals, // object, undefined
...resetConfig
} = argv
const mpType = argvComponent ? 'component' : 'page'
Expand Down Expand Up @@ -142,6 +143,11 @@ function mergeArgvConfig (config) {
const assetsRoot = path.resolve(outputPath)
defConfig.assetsRoot = assetsRoot
}

// 外部扩展
if (argvExternals && typeof argvExternals === 'object') {
defConfig.externals = argvExternals
}

const allEntry = Object.keys(defConfig.entry)

Expand Down