1.0.0 • Published 7 years ago
weex-jsonp-webpack-plugin v1.0.0
WeexJsonpWebpackPlugin
用于在 Weex 上实现 Code Splitting 加载。
在 Webpack 2 上跑通,其他版本的 Webpack 未测试。
Usage
在工程里面使用异步模块。
<div>
<text-din>Hello World</text-din>
</div>
export default {
components: {
TextDin: () => System.import(/* webpackChunkName: "text-din" */'path/to/text-din.vue')
}
};
在 Webpack 里配置:
const WeexJsonpPlugin = require('weex-jsonp-webpack-plugin');
module.exports = {
// other configs
plugins: [
new WeexJsonpPlugin({ publicPath: '' })
]
};
Options
publicPath
此项服务于如下原因:
- 在浏览器里面允许省略协议头或者使用相对路径,但是 Weex 内的网络请求应当是完整的 URL
- 可能要区分 CDN 资源
此值布尔假的时候,取 output.publicPath
的值。
一个使用案例是:
const IP = require('dev-ip')().shift();
// 注意是直接注入到 JS Bundle 内的
const publicPath = JSON.stringify(process.env.NODE_ENV === 'production'
? 'https://path/to/chunk/'
: 'http://'.concat(IP, ':', process.env.PORT || 8800, '/')
);
1.0.0
7 years ago