Skip to content

Commit d2d69f2

Browse files
committed
update
1 parent 5c92736 commit d2d69f2

File tree

3 files changed

+65
-4
lines changed

3 files changed

+65
-4
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# webpack-mpvue-plugin
1+
# webpack-mpvue-vendor-plugin
22

3-
> mpvue 资源路径解析插件
3+
> mpvue global 修正
44
55
## 使用示例:
66

77
```js
8-
const MpvuePlugin = require('webpack-mpvue-asset-plugin')
8+
const mpvueVendorPlugin = require('webpack-mpvue-vendor-plugin')
99
// webpack config
1010
{
1111
entry: [],
@@ -14,7 +14,7 @@ const MpvuePlugin = require('webpack-mpvue-asset-plugin')
1414
filename: 'foo.bundle.js'
1515
},
1616
plugins: [
17-
new MpvuePlugin()
17+
new mpvueVendorPlugin()
1818
]
1919
};
2020
```

index.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// vendor.js 文本替换
2+
// g = (function() {
3+
// return this;
4+
// })();
5+
6+
// g = (function() {
7+
// return typeof global !== 'undefined' ? global : this;
8+
// })();
9+
10+
function mpvueVendorPlugin() {
11+
}
12+
13+
mpvueVendorPlugin.prototype.apply = function (compiler) {
14+
compiler.plugin('emit', (compilation, callback) => {
15+
const fileName = 'common/vendor.js';
16+
const asset = compilation.assets[fileName];
17+
let fileContent = asset.source();
18+
19+
compilation.assets[fileName] = {
20+
source: () => {
21+
let from = /g\s=\s\(function\(\)\s\{\r?\n?\s+return\sthis;\r?\n?\s*\}\)\(\)\;/;
22+
let to = `g = (function() { return typeof global !== 'undefined' ? global : this; })();`
23+
fileContent = fileContent.replace(from, to)
24+
return fileContent;
25+
},
26+
size: () => {
27+
return Buffer.byteLength(fileContent, 'utf8');
28+
}
29+
};
30+
callback();
31+
});
32+
};
33+
34+
module.exports = mpvueVendorPlugin;

package.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "webpack-mpvue-vendor-plugin",
3+
"version": "0.0.1",
4+
"main": "index.js",
5+
"directories": {
6+
"lib": "lib"
7+
},
8+
"scripts": {
9+
"test": "echo \"Error: no test specified\" && exit 1"
10+
},
11+
"author": "hucq <chengquan.hu@gmail.com>",
12+
"license": "MIT",
13+
"devDependencies": {},
14+
"repository": {
15+
"type": "git",
16+
"url": "git+https://github.com/mpvue/webpack-mpvue-vendor-plugin.git"
17+
},
18+
"keywords": [
19+
"mpvue"
20+
],
21+
"bugs": {
22+
"url": "https://github.com/mpvue/webpack-mpvue-vendor-plugin/issues"
23+
},
24+
"homepage": "https://github.com/mpvue/webpack-mpvue-vendor-plugin#readme",
25+
"description": "",
26+
"dependencies": {}
27+
}

0 commit comments

Comments
 (0)