记一个简单的webpack.config.js

时间:2021-10-30 08:51:45
module.exports = {    entry: './basic/app.js',    output: {        path: './assets/',        filename: '[name].bundle.js'    },    module: {        loaders: [{            //babel-loader加载器,将es6转es5            test: /\.js$/,            loader: 'babel'        }, {            //style-loader,css-loader加载器,当调用bundle.js            //时动态生成sytle标签,插入html中的head            test: /\.css$/,            loader: 'style!css'        }]    }};

package.json 中的安装依赖

  "devDependencies": {    "babel-loader": "^6.2.5",    "babel-preset-es2015": "^6.16.0",    "css-loader": "^0.25.0",    "style-loader": "^0.13.1",    "webpack": "^1.13.2"  }

安装过程的坑

cnpm install webpack --save-devcnpm install babel-loader --save-devcnpm install css-loader --save-devcnpm install style-loader --save-dev

运行webpack 出现错误,后来查了babel-loader需要安装babel-preset-es2015包依赖

cnpm install babel-preset-es2015 --save-dev