-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
docs(configuration): document external script #3898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs(configuration): document external script #3898
Conversation
|
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/webpack-docs/webpack-js-org/3365yuafr |
101ebd9 to
a236dee
Compare
a236dee to
ef578b5
Compare
|
|
||
| There're two syntaxes for loading external script in webpack configuration: | ||
|
|
||
| 1. `{externals: {packageName: ['http://example.com/script.js', 'global', 'property', 'property']}}` (properties are optional) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These example snippets are less readable than for example just showing the syntax in the code snippet. Also properties are not described well. I suggest you do two full config examples for each of the syntaxes with more details on property, property use-cases and usage.
|
|
||
| External script can be loaded from any url when `externalsType` is set to `script`. | ||
|
|
||
| There're two syntaxes for loading external script in webpack configuration: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could rephrase this one when giving examples one by one
| - `'system'` | ||
| - `'promise'` - same as `'var'` but awaits the result (async module) | ||
| - `'import'` - uses `import()` to load a native EcmaScript module (async module) | ||
| - `'script'` - load script with HTML `<script>` element and use the global variable defined. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this more accessible than global variable defined? I think it assumes you understand context well enough
| - `'script'` - load script with HTML `<script>` element and use the global variable defined. | |
| - `'script'` - load script with HTML `<script>` element and store the result in a selected global variable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about?:
load script exposing predefined global variables with HTML
<script>element
From what I learned so far, we can only load external scripts here with <script> element when they expose predefined global variables like jquery did with global window.jQuery and window.$, otherwise it'll fail. Also we can't use random variable name but those predefined ones in global placeholder. (I'm not 100% sured here, maybe @sokra can help confirm this)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah reads much better and also makes sense, lets get Tobias to comment if this is right tho
Co-authored-by: Eugene Hlushko <jhlushko@gmail.com>
|
Thanks! |
closes #3806
Related issue #3772