Skip to content

Commit

Permalink
Merge pull request #16 from Charway/add-external-option
Browse files Browse the repository at this point in the history
add external option
  • Loading branch information
hucq authored Jan 11, 2019
2 parents c596813 + c76987d commit f820df5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
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

0 comments on commit f820df5

Please sign in to comment.