WEBPACK基本配置
1.cnpm install webpack babel-loader -D
2.配置webpack.config.js,配置如下;
module.exports = { entry:'./src/index.js',//入口文件 output:{ path:__dirname,//获取当前目录 filename:'./build/bundle.js'//创建build文件夹和budle.js文件 }, module:{ rules:[{ //模块验证规则 test:/\.js?$/, //以js结尾 exclude:/(node_modules)/, //忽略第三方插件 loader:'babel-loader' //编译器选择 }] } }
3.配置package.json如下
{ "name": "es6", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "start": "webpack", "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", "devDependencies": { "babel-core": "^6.26.3", "babel-loader": "^7.1.5", "babel-preset-es2015": "^6.24.1", "babel-preset-latest": "^6.24.1", "webpack": "^4.16.3" } }
4.运行npm start