1.在項目中添加loader依賴
在2-2章節(jié)中已經(jīng)運行過該命令
npm install style-loader css-loader -save
可在package.json中看到
2. 修改package.js文件
main: “bundle.js”
3.新建webpack.config.js
let webpack = ?require('webpack');
module.exports = {
? entry: 'index.js',
? output: {
? ? path: __dirname,
? ? filename: 'bundle.js'
? },
? module: {
? ? loaders: [{test: /\.css$/, loader: 'style-loader!css-loader'}]
? }
}
修改index.js
require('./css/index.css');
在cmd中運行命令
webpack
完成編譯過程