-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[DOCS] webpack documentation concept and config section from CommonJS to ESM #7731
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
6055f19
55a4582
00500d3
4b507b7
28a49cf
061a951
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,7 @@ Usage: `entry: string | [string]` | |
| **webpack.config.js** | ||
|
|
||
| ```javascript | ||
| module.exports = { | ||
| export default { | ||
| entry: './path/to/my/entry/file.js', | ||
| }; | ||
| ``` | ||
|
|
@@ -33,7 +33,7 @@ The single entry syntax for the `entry` property is a shorthand for: | |
| **webpack.config.js** | ||
|
|
||
| ```javascript | ||
| module.exports = { | ||
| export default { | ||
| entry: { | ||
| main: './path/to/my/entry/file.js', | ||
| }, | ||
|
|
@@ -45,7 +45,7 @@ We can also pass an array of file paths to the `entry` property which creates wh | |
| **webpack.config.js** | ||
|
|
||
| ```javascript | ||
| module.exports = { | ||
| export default { | ||
| entry: ['./src/file_1.js', './src/file_2.js'], | ||
| output: { | ||
| filename: 'bundle.js', | ||
|
|
@@ -62,7 +62,7 @@ Usage: `entry: { <entryChunkName> string | [string] } | {}` | |
| **webpack.config.js** | ||
|
|
||
| ```javascript | ||
| module.exports = { | ||
| export default { | ||
| entry: { | ||
| app: './src/app.js', | ||
| adminApp: './src/adminApp.js', | ||
|
|
@@ -91,7 +91,7 @@ An object of entry point description. You can specify the following properties. | |
| **webpack.config.js** | ||
|
|
||
| ```javascript | ||
| module.exports = { | ||
| export default { | ||
| entry: { | ||
| a2: 'dependingfile.js', | ||
| b2: { | ||
|
|
@@ -107,7 +107,7 @@ module.exports = { | |
| **webpack.config.js** | ||
|
|
||
| ```javascript | ||
| module.exports = { | ||
| export default { | ||
| entry: { | ||
| a2: './a', | ||
| b2: { | ||
|
|
@@ -122,7 +122,7 @@ module.exports = { | |
| Make sure `runtime` must not point to an existing entry point name, for example the below config would throw an error: | ||
|
|
||
| ```javascript | ||
| module.exports = { | ||
| export default { | ||
| entry: { | ||
| a1: './a', | ||
| b1: { | ||
|
|
@@ -136,7 +136,7 @@ module.exports = { | |
| Also `dependOn` must not be circular, the following example again would throw an error: | ||
|
|
||
| ```javascript | ||
| module.exports = { | ||
| export defualt { | ||
|
||
| entry: { | ||
| a3: { | ||
| import: './a', | ||
|
|
@@ -159,7 +159,7 @@ Below is a list of entry configurations and their real-world use cases: | |
| **webpack.config.js** | ||
|
|
||
| ```javascript | ||
| module.exports = { | ||
| export deafult { | ||
|
||
| entry: { | ||
| main: './src/app.js', | ||
| vendor: './src/vendor.js', | ||
|
|
@@ -170,7 +170,7 @@ module.exports = { | |
| **webpack.prod.js** | ||
|
|
||
| ```javascript | ||
| module.exports = { | ||
| export default { | ||
| output: { | ||
| filename: '[name].[contenthash].bundle.js', | ||
| }, | ||
|
|
@@ -180,7 +180,7 @@ module.exports = { | |
| **webpack.dev.js** | ||
|
|
||
| ```javascript | ||
| module.exports = { | ||
| export default { | ||
| output: { | ||
| filename: '[name].bundle.js', | ||
| }, | ||
|
|
@@ -198,7 +198,7 @@ T> In webpack version < 4 it was common to add vendors as a separate entry point | |
| **webpack.config.js** | ||
|
|
||
| ```javascript | ||
| module.exports = { | ||
| export default { | ||
| entry: { | ||
| pageOne: './src/pageOne/index.js', | ||
| pageTwo: './src/pageTwo/index.js', | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,15 +26,13 @@ A webpack **plugin** is a JavaScript object that has an [`apply`](https://develo | |
| ```javascript | ||
| const pluginName = 'ConsoleLogOnBuildWebpackPlugin'; | ||
|
|
||
| class ConsoleLogOnBuildWebpackPlugin { | ||
| export default class ConsoleLogOnBuildWebpackPlugin { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. corrected the typo error |
||
| apply(compiler) { | ||
| compiler.hooks.run.tap(pluginName, (compilation) => { | ||
| compiler.hooks.run.tap(pluginName, () => { | ||
|
||
| console.log('The webpack build process is starting!'); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| module.exports = ConsoleLogOnBuildWebpackPlugin; | ||
| ``` | ||
|
|
||
| It is recommended that the first parameter of the tap method of the compiler hook should be a camelized version of the plugin name. It is advisable to use a constant for this so it can be reused in all hooks. | ||
|
|
@@ -50,11 +48,11 @@ Depending on how you are using webpack, there are multiple ways to use plugins. | |
| **webpack.config.js** | ||
|
|
||
| ```javascript | ||
| const HtmlWebpackPlugin = require('html-webpack-plugin'); | ||
| const webpack = require('webpack'); //to access built-in plugins | ||
| const path = require('path'); | ||
| import HtmlWebpackPlugin from 'html-webpack-plugin'); | ||
| import webpack from 'webpack'; //to access built-in plugins | ||
| import path from 'path'; | ||
|
|
||
| module.exports = { | ||
| export default { | ||
| entry: './path/to/my/entry/file.js', | ||
| output: { | ||
| filename: 'my-first-webpack.bundle.js', | ||
|
|
@@ -84,10 +82,10 @@ When using the Node API, you can also pass plugins via the `plugins` property in | |
| **some-node-script.js** | ||
|
|
||
| ```javascript | ||
| const webpack = require('webpack'); //to access webpack runtime | ||
| const configuration = require('./webpack.config.js'); | ||
| import webpack from 'webpack'; //to access webpack runtime | ||
| import configuration from './webpack.config.js'; | ||
|
|
||
| let compiler = webpack(configuration); | ||
| const compiler = webpack(configuration); | ||
|
|
||
| new webpack.ProgressPlugin().apply(compiler); | ||
|
|
||
|
|
||
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.
the S in script should be capitalized