1. cnpm i webpack -g //全局安装webpack
2. 新建文件夹 app APP文件夹下新建 index.html style.css second.js
2. 在app文件夹下新建 index.js文件 require(‘./style.css’)加载css文件 require(‘./second.js’) 加载js文件
3. app同级文件下新建 webpack.config.js
let path = require('path');
module.exports = {
entry: "./app/first.js", //入口文件
output: {
filename: 'dist/bundle.js', //出口文件
path: __dirname
},
module:{
loaders: [
{
test: /\.css$/,
loader: 'style-loader!css-loader'
}
]
}
}
4. 命令行输入 npm init 生成package.json 找到scripts对象 加入 “start”: “webpack --watch”
5. cnpm i style-loader css-loader -D 加载loader
6. 执行命令 npm run start