Skip to content

Commit 6c87073

Browse files
authored
Merge pull request #19 from christophersmith262/bugfix/fix-external-dependencies
Fix external dependencies
2 parents e6790a1 + ebf70b0 commit 6c87073

3 files changed

Lines changed: 13 additions & 15 deletions

File tree

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const DrupalLibrariesPlugin = require('drupal-libraries-webpack-plugin');
3030

3131
module.exports = {
3232
plugins: [
33-
new DrupalLibrariesPlugin()
33+
new DrupalLibrariesPlugin()
3434
],
3535
};
3636
```
@@ -45,6 +45,14 @@ You can explicitly add a Drupal library dependency to module by using a special
4545
require('@drupal(core/jquery)')
4646
```
4747

48+
Drupal libraries must be added as [external dependencies](https://webpack.js.org/configuration/externals/) in your webpack configuration:
49+
50+
```js
51+
externals: {
52+
'@drupal(drupal/core)': 'Drupal'
53+
}
54+
```
55+
4856
### Configuration
4957

5058
#### `path`
@@ -137,7 +145,7 @@ module.exports = {
137145
plugins: [
138146
new DrupalLibrariesPlugin({
139147
// Only pick up require('jquery') or require('Drupal') statements.
140-
libraryPattern: /^(jquery|Drupal)$/
148+
requirePattern: /^(jquery|Drupal)$/
141149
})
142150
],
143151
};

lib/DrupalLibrariesPlugin.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,6 @@ class DrupalLibrariesPlugin {
4949
* The webpack compiler.
5050
*/
5151
apply(compiler) {
52-
// Prevents drupal library dependencies from being included.
53-
compiler.hooks.normalModuleFactory.tap('DrupalLibrariesPlugin', cmf => {
54-
cmf.hooks.factorize.tapAsync("DrupalLibrariesPlugin", (data, callback) => {
55-
const result = this.opts.requirePattern.exec(data.request)
56-
if (result) {
57-
callback(null, new DrupalLibraryModule(result[1]))
58-
}
59-
else {
60-
return callback()
61-
}
62-
})
63-
})
64-
6552
// Analyzes the final chunks to determine library dependencies.
6653
compiler.hooks.done.tapPromise('DrupalLibrariesPlugin', async stats => {
6754
this.metadata = await this._generateLibraryMetadata(stats.compilation)

test/library-dependency.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ test('Generates a library entry for @drupal(core/drupal)', async () => {
66
entry: {
77
'require-drupal': path.resolve(__dirname, './fixtures/require-drupal.es6.js'),
88
},
9+
externals: {
10+
'@drupal(drupal/core)': 'Drupal'
11+
}
912
})).result
1013

1114
expect(result).toEqual({

0 commit comments

Comments
 (0)