npm init

初始化 生成pack.json

npm install webpack webpack-cli —save-dev

安装webpack和webapck-cli

创建项目结构

product
|- package.json
|- src
|-asset
|- main.js
|- dist
|- index.html

output

filename

使用入口名称

  1. module.exports = {
  2. output: {
  3. filename:"[name].bundle.js"
  4. }
  5. }

使用内部 chunk id

  1. module.exports = {
  2. output: {
  3. filename:"[id].bundle.js"
  4. }
  5. }

使用由生成内容产生的hash

  1. module.exports = {
  2. output: {
  3. filename:"[contenthash].bundle.js"
  4. }
  5. }

output.path

output路径对应一个绝对路径

  1. const path = require('path');
  2. moudule.exports = {
  3. output:{
  4. filename: "js/[contenthash].bundle.js",
  5. path :path.resolve(__dirname,'dist')
  6. }
  7. }