webpack4安装测试

package.json

{
  "scripts": {
    "start": "webpack-dev-server --config build/webpack.config.js --mode development",
    "build": "webpack --mode development --config build/webpack.config.js"
  },
  "dependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.4",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-es2015-loose": "^8.0.0",
    "babel-preset-react": "^6.24.1",
    "react": "^16.4.0",
    "react-dom": "^16.4.0",
    "webpack": "^4.10.2",
    "webpack-cli": "^2.1.4"
  },
  "devDependencies": {
    "html-webpack-plugin": "^3.2.0",
    "webpack-dev-server": "^3.1.4"
  }
}

没有package.json的执行下面命令

npm init

将上面的配置加入package.json
然后执行

npm install

运行

运行webpack-dev-server

npm run start

打包

npm run build

git

因为网上教程都很多坑,所以直接简化,放到git上一个最初始的文件环境: https://github.com/shulinqian/webpack4_react_base
你可以fork回去修改,或者直接克隆下拉

git clone https://github.com/shulinqian/webpack4_react_base.git

说明:

webpack4中将命令行相关的都迁移至 webpack-cli 包,所有要安装后才会执行命令,否则会一直提示你选择命令

标签: 无

发表评论: