@@ -2,7 +2,8 @@ const path = require('path'),
22 YAML = require ( 'yaml' ) ,
33 DrupalLibraryEntryGenerator = require ( './DrupalLibraryEntryGenerator' ) ,
44 DrupalLibraryFile = require ( './DrupalLibraryFile' ) ,
5- DrupalLibraryMetadata = require ( './DrupalLibraryMetadata' )
5+ DrupalLibraryMetadata = require ( './DrupalLibraryMetadata' ) ,
6+ DrupalLibraryModule = require ( './DrupalLibraryModule' )
67
78/**
89 * A webpack plugin for generating drupal libraries files.
@@ -49,7 +50,21 @@ class DrupalLibrariesPlugin {
4950 * The webpack compiler.
5051 */
5152 apply ( compiler ) {
52- compiler . hooks . done . tapPromise ( 'DrupalLibrariesPlugin ' , async stats => {
53+ // Prevents drupal library dependencies from being included.
54+ compiler . hooks . normalModuleFactory . tap ( 'DrupalLibrariesPlugin' , cmf => {
55+ cmf . hooks . factory . tap ( "DrupalLibrariesPlugin" , factory => ( data , callback ) => {
56+ const result = this . opts . requirePattern . exec ( data . request )
57+ if ( result ) {
58+ callback ( null , new DrupalLibraryModule ( result [ 1 ] ) )
59+ }
60+ else {
61+ factory ( data , callback )
62+ }
63+ } )
64+ } )
65+
66+ // Analyzes the final chunks to determine library dependencies.
67+ compiler . hooks . done . tapPromise ( 'DrupalLibrariesPlugin' , async stats => {
5368 this . metadata = await this . _generateLibraryMetadata ( stats . compilation )
5469 this . result = await this . _generateLibraries ( this . metadata )
5570 this . files = await Promise . resolve ( this . opts . path ( this . result , this . metadata ) )
0 commit comments