File tree Expand file tree Collapse file tree 3 files changed +65
-4
lines changed Expand file tree Collapse file tree 3 files changed +65
-4
lines changed Original file line number Diff line number Diff line change 1
- # webpack-mpvue-plugin
1
+ # webpack-mpvue-vendor- plugin
2
2
3
- > mpvue 资源路径解析插件
3
+ > mpvue global 修正
4
4
5
5
## 使用示例:
6
6
7
7
``` js
8
- const MpvuePlugin = require (' webpack-mpvue-asset -plugin' )
8
+ const mpvueVendorPlugin = require (' webpack-mpvue-vendor -plugin' )
9
9
// webpack config
10
10
{
11
11
entry: [],
@@ -14,7 +14,7 @@ const MpvuePlugin = require('webpack-mpvue-asset-plugin')
14
14
filename: ' foo.bundle.js'
15
15
},
16
16
plugins: [
17
- new MpvuePlugin ()
17
+ new mpvueVendorPlugin ()
18
18
]
19
19
};
20
20
```
Original file line number Diff line number Diff line change
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 \( f u n c t i o n \( \) \s \{ \r ? \n ? \s + r e t u r n \s t h i s ; \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 ;
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments