Update webpack.md

master
Matt Huntington 7 years ago committed by GitHub
parent dc1df4f3b1
commit f7911d4731
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -21,6 +21,8 @@ npm init
npm install webpack --save-dev npm install webpack --save-dev
``` ```
If you're asked, install `webpack-cli` as well.
Create a test file: Create a test file:
``` ```
@ -167,7 +169,7 @@ Create `webpack.config.js` to simplify the terminal command
module.exports = { module.exports = {
entry: './js/index.js', entry: './js/index.js',
output: { output: {
filename: 'bundle.js' filename: 'dist/bundle.js'
} }
}; };
``` ```
@ -206,7 +208,7 @@ Modify the webpack config to use these:
module.exports = { module.exports = {
entry: './js/index.js', entry: './js/index.js',
output: { output: {
filename: 'bundle.js' filename: 'dist/bundle.js'
}, },
module: { module: {
rules: [ rules: [
@ -234,7 +236,7 @@ class Foo {
} }
``` ```
The result in `dist/build.js` is the ES5 version (may be minified): The result in `dist/build.js` is the ES5 version:
```javascript ```javascript
var Foo = function () { var Foo = function () {
@ -335,30 +337,3 @@ and it will open up your browser automatically. Change a file, and see it reloa
``` ```
rm -r dist rm -r dist
``` ```
Change your script tag to be
```html
<script src="main.js" charset="utf-8"></script>
```
And take out the `output` property in webpack.config.js
```javascript
module.exports = {
entry: './js/index.js',
module: {
rules: [
{
test: /\.(js|jsx)$/, //for all files that end with js/jsx
use: {
loader: 'babel-loader', //use the babel loader to load:
options: {
presets: ["es2015", "react"] //the es2015 compiler
}
}
}
]
}
};
```

Loading…
Cancel
Save