You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/api/module-methods.mdx
+6-2Lines changed: 6 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,7 @@ contributors:
14
14
- jamesgeorge007
15
15
- WofWca
16
16
- snitin315
17
+
- adriancuadrado
17
18
related:
18
19
- title: CommonJS Wikipedia
19
20
url: https://en.wikipedia.org/wiki/CommonJS
@@ -97,7 +98,8 @@ W> This feature relies on [`Promise`](https://developer.mozilla.org/en-US/docs/W
97
98
98
99
It is not possible to use a fully dynamic import statement, such as `import(foo)`. Because `foo` could potentially be any path to any file in your system or project.
99
100
100
-
The `import()` must contain at least some information about where the module is located. Bundling can be limited to a specific directory or set of files so that when you are using a dynamic expression - every module that could potentially be requested on an `import()` call is included. For example, ``import(`./locale/${language}.json`)`` will cause every `.json` file in the `./locale` directory to be bundled into the new chunk. At run time, when the variable `language` has been computed, any file like `english.json` or `german.json` will be available for consumption.
101
+
The `import()` must contain at least some information about where the module is located. Bundling can be limited to a specific directory or set of files so that when you are using a dynamic expression - every module that could potentially be requested on an `import()` call is included.
102
+
For example, ``import(`./locale/${language}.json`)`` will only bundle all `.json` files in the `./locale` directory and subdirectories into the new chunk and exclude files with other file extensions. At run time, when the variable `language` has been computed, any file like `english.json` or `german.json` will be available for consumption.
101
103
102
104
```javascript
103
105
// imagine we had a method to get language from cookies or other storage
@@ -111,7 +113,7 @@ T> Using the [`webpackInclude` and `webpackExclude`](/api/module-methods/#magic-
111
113
112
114
#### Magic Comments
113
115
114
-
Inline comments to make features work. By adding comments to the import, we can do things such as name our chunk or select different modes. For a full list of these magic comments see the code below followed by an explanation of what these comments do.
116
+
By adding comments to the import, we can do things such as name our chunk or select different modes. For a full list of these magic comments see the code below followed by an explanation of what these comments do.
@@ -153,7 +153,7 @@ _People passionate about Webpack (In no particular order)_
153
153
-[CSS Cleanup Webpack Plugin](https://github.com/do-web/css-cleanup-webpack-plugin) - A plugin to remove duplicated and unused css rules -- _Maintainer_: `Dominik Weber`[![Github][githubicon]](https://github.com/do-web)
154
154
-[Extension Reloader](https://github.com/rubenspgcavalcante/webpack-extension-reloader) - Hot reloading while developing browser extensions -- _Maintainer_: `Rubens P. G. Cavalcante`[![Github][githubicon]](https://github.com/rubenspgcavalcante)[![Twitter][twittericon]](https://twitter.com/rubenspgc)
155
155
-[Htmls Webpack Plugin](https://github.com/zaaack/htmls-webpack-plugin): Simple and fast multiple-htmls-generating plugin for webpack. -- _Maintainer_: `Zack Young`[![Github][githubicon]](https://github.com/zaaack)[![Twitter][twittericon]](https://twitter.com/ZaaackYoung)
-[build-hash-webpack-plugin](https://github.com/Cosium/build-hash-webpack-plugin) For each build, Webpack generates an in-memory hash allowing to know if two build outputs are the same or not. This plugin writes the described build hash in a separate json file. -- _Maintainer_: `Réda Housni Alaoui`[![Github][githubicon]](https://github.com/reda-alaoui)[![Twitter][twittericon]](https://twitter.com/alaouirda)
159
159
-[webpack-hook-plugin](https://github.com/tienne/webpack-hook-plugin) - run any shell commands before or after webpack builds -- _Maintainer_: `David Kwon`[![Github][githubicon]](https://github.com/tienne)
Copy file name to clipboardExpand all lines: src/content/guides/getting-started.mdx
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,6 +27,7 @@ contributors:
27
27
- d3lm
28
28
- snitin315
29
29
- Etheryen
30
+
- zowiebeha
30
31
---
31
32
32
33
Webpack is used to compile JavaScript modules. Once [installed](/guides/installation), you can interact with webpack either from its [CLI](/api/cli) or [API](/api/node). If you're still new to webpack, please read through the [core concepts](/concepts) and [this comparison](/comparison) to learn why you might use it over the other tools that are out in the community.
@@ -200,6 +201,8 @@ Now, since we'll be bundling our scripts, we have to update our `index.html` fil
200
201
</html>
201
202
```
202
203
204
+
T> A couple other script loading strategies exist. Deferred loading is one such alternative to the above, where instead scripts are consolidated into the `<head>` and are given the `defer` attribute. This strategy downloads the external script resource(s) in parallel with document parsing, and will execute the scripts in order of document appearance after parsing has finished. This is in contrast to the above, in which the parser pauses to download and then execute the external resource syncronously. To learn more about this process, MDN has a nice [`reference guide`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script#async_and_defer).
205
+
203
206
In this setup, `index.js` explicitly requires `lodash` to be present, and binds it as `_` (no global scope pollution). By stating what dependencies a module needs, webpack can use this information to build a dependency graph. It then uses the graph to generate an optimized bundle where scripts will be executed in the correct order.
204
207
205
208
With that said, let's run `npx webpack`, which will take our script at `src/index.js` as the [entry point](/concepts/entry-points), and will generate `dist/main.js` as the [output](/concepts/output). The `npx` command, which ships with Node 8.2/npm 5.2.0 or higher, runs the webpack binary (`./node_modules/.bin/webpack`) of the webpack package we installed in the beginning:
0 commit comments