Skip to content

Conversation

@chenxsan
Copy link
Member

@chenxsan chenxsan commented Aug 6, 2020

closes #3806

Related issue #3772

@vercel
Copy link

vercel bot commented Aug 6, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/webpack-docs/webpack-js-org/3365yuafr
✅ Preview: https://webpack-js-org-git-fork-chenxsan-feature-document-script-48e1bb.webpack-docs.vercel.app


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)
Copy link
Member

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:
Copy link
Member

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.
Copy link
Member

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

Suggested change
- `'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

Copy link
Member Author

@chenxsan chenxsan Aug 11, 2020

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)

Copy link
Member

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>
@chenxsan chenxsan marked this pull request as draft August 11, 2020 14:12
@chenxsan chenxsan closed this Aug 12, 2020
@chenxsan chenxsan reopened this Aug 12, 2020
@chenxsan chenxsan marked this pull request as ready for review August 15, 2020 00:56
@EugeneHlushko EugeneHlushko merged commit 8dd2a8c into webpack:master Aug 18, 2020
@EugeneHlushko
Copy link
Member

Thanks!

@chenxsan chenxsan deleted the feature/document-script-externalsType branch August 23, 2020 02:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document webpack change: avoid collision in data-webpack by adding the uniqueName

2 participants