webpack的三种运行方式

第一种:

  没有webpack.cofig.js文件使用默认配置文件的时候 在命令行输入 npx  webpack  index.js (接口文件为index.js)

第二种:

  有webpack.cofig.js文件  在命令行输入npx  webpack

const path = require('path');
module.exports = {
    entry:'./src/index.js',
    output:{
        //生成的接口文件 
        filename:'bundle.js',
        //生成的bundle.js文件放置在dist文件中
        path:path.resolve(__dirname,'dist')
    }
}

 第三种:

   有webpack.cofig.js文件  在命令行输入npx  run bundle(需要将package.json更改

{
  "name": "webpackcase",
  "version": "1.0.0",
  "description": "",
  "private": true,
  "scripts": {
    "bundle": "webpack"//更改的部分
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "webpack": "^4.37.0",
    "webpack-cli": "^3.3.6"
  }
}

)

猜你喜欢

转载自www.cnblogs.com/rickyctbur/p/11262278.html