File tree Expand file tree Collapse file tree 2 files changed +65
-0
lines changed Expand file tree Collapse file tree 2 files changed +65
-0
lines changed Original file line number Diff line number Diff line change
1
+ function MpvuePlugin ( ) { }
2
+
3
+ MpvuePlugin . prototype . apply = function ( compiler ) {
4
+ const { options : { entry, plugins} } = compiler ;
5
+ compiler . plugin ( 'emit' , function ( compilation , callback ) {
6
+ let commonsChunkNames = [ ] ;
7
+ // 获取所有的 chunk name
8
+ plugins . forEach ( item => {
9
+ let { chunkNames } = item ;
10
+ if ( item . constructor . name === 'CommonsChunkPlugin' && chunkNames ) {
11
+ commonsChunkNames = commonsChunkNames . concat ( chunkNames ) ;
12
+ }
13
+ } )
14
+ let pages = Object . keys ( entry ) ;
15
+ compilation . chunks . forEach ( commonChunk => {
16
+ const { files, chunks : childChunks , name } = commonChunk ;
17
+ let commonWxssFile = files . find ( item => item . endsWith ( '.wxss' ) ) ;
18
+
19
+ if ( commonsChunkNames . indexOf ( name ) > - 1 && commonWxssFile ) {
20
+ childChunks . forEach ( item => {
21
+ let wxssFile = item . files . find ( item => item . endsWith ( '.wxss' ) ) ;
22
+ if ( item . name === 'app' && wxssFile ) { // 过滤 app
23
+ return ;
24
+ }
25
+ try {
26
+ let wxss = compilation . assets [ wxssFile ] . source ( ) ;
27
+ wxss = `@import "/${ commonWxssFile } ";\n${ wxss } ` ;
28
+ compilation . assets [ wxssFile ] . source = ( ) => wxss ;
29
+ } catch ( error ) {
30
+ console . error ( error , wxssFile )
31
+ }
32
+ } )
33
+ }
34
+ } ) ;
35
+ callback ( ) ;
36
+ } ) ;
37
+ } ;
38
+
39
+ module . exports = MpvuePlugin ;
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " webpack-mpvue-asset-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" : " rememberwz <rememberwz@gmail.com>" ,
12
+ "license" : " MIT" ,
13
+ "devDependencies" : {},
14
+ "repository" : {
15
+ "type" : " git" ,
16
+ "url" : " git+https://github.com/mpvue/webpack-mpvue-asset-plugin.git"
17
+ },
18
+ "keywords" : [
19
+ " mpvue"
20
+ ],
21
+ "bugs" : {
22
+ "url" : " https://github.com/mpvue/webpack-mpvue-asset-plugin/issues"
23
+ },
24
+ "homepage" : " https://github.com/mpvue/webpack-mpvue-asset-plugin#readme" ,
25
+ "description" : " "
26
+ }
You can’t perform that action at this time.
0 commit comments