@@ -29,10 +29,18 @@ const getCriticalDependencyWarning = memoize(() =>
2929) ;
3030
3131class ImportMetaPlugin {
32+ /**
33+ * @param {import("../../declarations/WebpackOptions").ImportMeta } options options
34+ */
35+ constructor ( options ) {
36+ this . options = options ;
37+ }
38+
3239 /**
3340 * @param {Compiler } compiler compiler
3441 */
3542 apply ( compiler ) {
43+ const options = this . options ;
3644 compiler . hooks . compilation . tap (
3745 "ImportMetaPlugin" ,
3846 ( compilation , { normalModuleFactory } ) => {
@@ -49,6 +57,8 @@ class ImportMetaPlugin {
4957 * @returns {void }
5058 */
5159 const parserHandler = ( parser , parserOptions ) => {
60+ if ( options === false ) return ;
61+
5262 /// import.meta direct ///
5363 parser . hooks . typeof
5464 . for ( "import.meta" )
@@ -106,14 +116,16 @@ class ImportMetaPlugin {
106116 parser . hooks . evaluateTypeof
107117 . for ( "import.meta.url" )
108118 . tap ( "ImportMetaPlugin" , evaluateToString ( "string" ) ) ;
109- parser . hooks . evaluateIdentifier
110- . for ( "import.meta.url" )
111- . tap ( "ImportMetaPlugin" , expr => {
112- return new BasicEvaluatedExpression ( )
113- . setString ( getUrl ( parser . state . module ) )
114- . setRange ( expr . range ) ;
115- } ) ;
116119
120+ if ( options . url ) {
121+ parser . hooks . evaluateIdentifier
122+ . for ( "import.meta.url" )
123+ . tap ( "ImportMetaPlugin" , expr => {
124+ return new BasicEvaluatedExpression ( )
125+ . setString ( getUrl ( parser . state . module ) )
126+ . setRange ( expr . range ) ;
127+ } ) ;
128+ }
117129 /// import.meta.webpack ///
118130 const webpackVersion = parseInt (
119131 require ( "../../package.json" ) . version ,
0 commit comments