webpack 安装和使用

2020-04-27  本文已影响0人  遗忘的灬誓言

1.全局安装:npm install webpack -g
指定版本:npm install webpack@3.6.0 -g
2.局部安装:npm install webpack --save-dev
指定版本:npm install webpack@3.6.0 --save-dev

3.打包项目:
初始化:npm init -y (需要使用node 方面的东西之前一定要初始化)
打包: webpack ./src/main.js ./dist/bundle.js

项目中创建:webpack.config.js

   var path = require('path');
   module.exports = {
    entry:"./src/main.js",
    output: {
        path:path.resolve(__dirname,"dist"),//动态获取绝对路径
        filename: 'bundle.js'
    },
};

打包:webpack

package.json中加入build

{
  "name": "wabpack",//包名
  "version": "1.0.0",//版本号
  "description": "",//描述
  "main": "index.js",//入口
  "dependencies": {
    "webpack": "^3.6.0"
  },
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build":"webpack"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

打包:npm run build

总结:一脸懵逼

上一篇下一篇

猜你喜欢

热点阅读