@@ -31,6 +31,16 @@ module.exports = {
3131};
3232```
3333
34+ By default, when you compile webpack, the drupal library file will be generated to 'webpack.libraries.yml'.
35+
36+ The plugin will automatically figure out what libraries need to depend on other libraries based on the final webpack chunks.
37+
38+ You can explicitly add a Drupal library dependency to module by using a special ` require ` statement:
39+
40+ ``` js
41+ require (' @drupal(core/jquery)' )
42+ ```
43+
3444### Configuration
3545
3646#### ` path `
@@ -84,11 +94,52 @@ module.exports = {
8494};
8595```
8696
87- #### ` prepareFile ` function example
97+ #### ` nameGenerator `
98+
99+ Type: ` Function `
100+
101+ Default: ` nameGenerator `
102+
103+ Generates a library name for a chunk.
104+
105+ #### Minimal example
106+
107+ ** webpack.config.js**
108+
109+ ``` js
110+ module .exports = {
111+ plugins: [
112+ new DrupalLibrariesPlugin ({
113+ nameGenerator : chunk => chunk .hash
114+ })
115+ ],
116+ };
117+ ```
118+
119+ #### ` requirePattern `
120+
121+ Type: ` String `
122+
123+ Default: ` /^@drupal\(([^\)]+)\)$/ `
124+
125+ The pattern to use for detecting drupal library dependencies.
126+
127+ ``` js
128+ module .exports = {
129+ plugins: [
130+ new DrupalLibrariesPlugin ({
131+ // always use the chunk hash as the library name.
132+ libraryPattern: / ^ (jquery| /
133+ })
134+ ],
135+ };
136+ ```
137+
138+ #### `prepareFile`
88139
89140Type: `Function`
90141
91- Default: ` DrupalLibrariesPlugin.defaults.prepareFile' `
142+ Default: `DrupalLibrariesPlugin. defaults. prepareFile`
92143
93144Prepares a library file that is about to be written.
94145
@@ -99,6 +150,10 @@ module.exports = {
99150 plugins: [
100151 new DrupalLibrariesPlugin({
101152 prepareFile: (file, compiler, compilation) => {
153+ // Add an extra entry to the file when outputting
154+ file. content['external'] = {
155+ remote: 'https:/ / external- library .js ' ,
156+ }
102157 return DupalLibrariesPlugin.defaults.prepareFile(file, compiler, compilation)
103158 },
104159 })
0 commit comments