天天看點

webpack-loader

webpack loader學習

step1

  • 安裝依賴
npm install --save-dev css-loader
npm install --save-dev style-loader
           

step2

  • 建立一個index.css
  • 在webpack 添加loader
var path = require('path');


module.exports = {
    entry:'./index.js',
    output:{
        path:path.join(__dirname,'dist'),
        filename:'bundle.js'
    },
    module:{
        rules:[
            { test: /\.css$/, use: 'css-loader' }
            ]
    }
}
           
  • 在index.js中引用css
require("!style-loader!css-loader!./index.css");
           
webpack-loader

繼續閱讀