Skip to content

Commit 993ac1a

Browse files
author
yangfan19
committed
解析ES6
1 parent bade00a commit 993ac1a

File tree

8 files changed

+1596
-3
lines changed

8 files changed

+1596
-3
lines changed

webpack-03/.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["@babel/preset-env"]
3+
}

webpack-03/README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# webpack-03
22

3-
## loaders的使用
3+
## 解析ES6
4+
5+
————
6+
### loaders和的Plugins使用
47
————
58
#### 日常使用的loader
69

@@ -15,4 +18,24 @@ raw-lodder // 将文件已字符串的形式导入
1518
thead-lodder // 多进程打包JS和css
1619
```
1720

21+
### Plugins的使用
22+
————
23+
#### 日常使用的Plugins
24+
25+
```shell
26+
CommonsChunkPlugin // 将chunks相同的模块代码提取成公共的js
27+
CleanWebpackPlugin // 清理构建目录
28+
ExtractTextWebpackPlugin // 将css从bunlde文件里提取到一个独立的css文件
29+
CopyWebpackPlugin // 将文件或者文件夹拷贝到构建的输出目录
30+
HtmlWebpackPlugin // 创建html文件去承载输出到bundle
31+
UglifyjsWebpackPligin // 压缩JS
32+
ZipWebpackPlugin // 将打包出的资源生成一个zip的包
33+
```
34+
35+
————
36+
## loader和 Plugins的区别?
37+
38+
loader不能做的事情Plugin都能干
39+
40+
1841

webpack-03/package-lock.json

Lines changed: 1545 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webpack-03/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
"author": "",
1212
"license": "ISC",
1313
"devDependencies": {
14+
"@babel/core": "^7.13.10",
15+
"@babel/preset-env": "^7.13.10",
16+
"babel-loader": "^8.2.2",
1417
"webpack": "^4.31.0",
1518
"webpack-cli": "^3.3.2"
1619
}

webpack-03/src/helloWorld.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function helloworld() {
2+
return 'Hello webpack';
3+
}

webpack-03/src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { helloworld } from './helloWorld';
2+
3+
document.write(helloworld());

webpack-03/src/search.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
document.write('search文件');

webpack-03/webpack.config.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,22 @@
33
const path = require('path');
44

55
module.exports = {
6-
entry: './src/index.js',
6+
entry: {
7+
// 入口文件可以用对象的形式来写
8+
index: './src/index.js',
9+
search: './src/search.js',
10+
},
711
output: {
812
path: path.join(__dirname, 'dist'),
9-
filename: 'bundle.js',
13+
filename: '[name].js', // 多个入口的情况下 不知道对应的名称、可以用占位符来指定[name]
1014
},
1115
mode: 'production',
16+
module: {
17+
rules: [
18+
{
19+
test: /.js$/,
20+
use: 'babel-loader',
21+
},
22+
],
23+
},
1224
};

0 commit comments

Comments
 (0)