Entry与Output

https://www.webpackjs.com/configuration/entry-context/

https://www.webpackjs.com/configuration/output/

默认output的文件名为mian.js

1
2
3
4
5
6
7
8
9
entry: {
'main': './src/index.js',
'sub': './src/index.js',
},

output: {
  filename: '[name].js',
  path: path.resolve(__dirname, 'dist')
}

会打包出main.jssub.js两个文件

如果配置

1
2
3
4
5
output: {
  publicPath: 'http://cdn.com.cn',
  filename: '[name].js',
  path: path.resolve(__dirname, 'dist')
}

生成的html

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
<!DOCTYPE html>
<html lang="zh">
<head>
  <meta charset="UTF-8">
  <title>html模板</title>
</head>
<body>
  <div id="root"></div>
<script type="text/javascript" src="http://cdn.com.cn/main.js"></script><script type="text/javascript" src="http://cdn.com.cn/sub.js"></script></body>
</html>