1
1
"use strict" ;
2
2
3
+ /**
4
+ * Matches the entire AMD header (excluding the webpack return statement)
5
+ * $1: e.g.: define("dojo/request/xhr", function(xhr) {
6
+ */
7
+ const replacementExpr = / ( d e f i n e \( \[ .* \] \, \s ? f u n c t i o n \( .* \) \s ? \{ \s ? r e t u r n .* ) \( f u n c t i o n \( [ a - z ] * \) \s ? \{ \s ? .* / ;
3
8
/**
4
9
* used to parse the AMD source built by webpack
5
10
* Matches the following items:
6
11
* - $1: extract the dependency list (e.g. "dojo/request/xhr")
7
12
* - $2: extract the variables referring to the dependency (e.g. "xhr")
8
- */
9
- const replacementExpr = / ( d e f i n e \( \[ .* \] \, \s ? f u n c t i o n \( .* \) \s ? \{ \s ? r e t u r n .* ) \( f u n c t i o n \( [ a - z ] * \) \s ? \{ \s ? .* / ;
10
- /**
11
- * Matches the entire AMD header (excluding the webpack return statement)
12
- * $1: e.g.: define("dojo/request/xhr", function(xhr) {
13
13
*/
14
14
const dependencyExtractorExpr = / d e f i n e \( \[ ( .* ) \] \, \s ? f u n c t i o n \( ( .* ) \) \s ? \{ \s ? r e t u r n .* ( \( f u n c t i o n \( [ a - z ] * \) \s ? \{ ) \s ? .* / ;
15
15
/** expression to catch the end of the webpack AMD file */
@@ -36,29 +36,35 @@ DojoModuleWrapperPlugin.prototype.apply = function(compiler) {
36
36
const moduleName = this . options [ chunk ] . moduleName || '' ;
37
37
38
38
let source = compilation . assets [ distChunk ] . source ( ) ;
39
-
40
39
const depExtractions = source . match ( dependencyExtractorExpr ) ;
41
- const toReplace = source . match ( replacementExpr ) [ 1 ] ;
40
+
41
+ if ( depExtractions != null ) {
42
+ const toReplace = source . match ( replacementExpr ) ;
43
+ if ( toReplace && toReplace . length == 1 ) {
44
+ source = source . replace ( toReplace [ 1 ] , "" ) ;
45
+ }
42
46
43
- const dojoDeclareLoaderStatement = this . generateStartStatement ( moduleName , depExtractions [ 1 ] , depExtractions [ 2 ] , baseUrl , fileNameSuffix ) ;
47
+ const dojoDeclareLoaderStatement = this . generateStartStatement ( moduleName , depExtractions [ 1 ] , depExtractions [ 2 ] , baseUrl , fileNameSuffix ) ;
44
48
45
- source = source . replace ( toReplace , "" ) ;
46
- source = source . replace ( endBracketExpr , endBracketString ) ;
49
+ source = source . replace ( endBracketExpr , endBracketString ) ;
47
50
48
- const newName = distChunk . substring ( 0 , distChunk . indexOf ( ".js" ) ) + fileNameSuffix ;
51
+ const newName = distChunk . substring ( 0 , distChunk . indexOf ( ".js" ) ) + fileNameSuffix ;
49
52
50
- compilation . assets [ newName ] = {
51
- source : function ( ) {
52
- return source ;
53
- } ,
54
- size : function ( ) {
55
- return source . length ;
56
- }
57
- } ;
53
+ compilation . assets [ newName ] = {
54
+ source : function ( ) {
55
+ return source ;
56
+ } ,
57
+ size : function ( ) {
58
+ return source . length ;
59
+ }
60
+ } ;
58
61
59
- compilation . assets [ distChunk ] . source = ( ) => {
60
- return dojoDeclareLoaderStatement ;
61
- } ;
62
+ compilation . assets [ distChunk ] . source = ( ) => {
63
+ return dojoDeclareLoaderStatement ;
64
+ } ;
65
+ } else {
66
+ console . log ( "No change detected. Skipping 'dojo-module-wrapper-webpack-plugin'" )
67
+ }
62
68
} ) ;
63
69
callback ( ) ;
64
70
} ) ;
0 commit comments