Sass热更新webpack配置

2019-05-09  本文已影响0人  Yokiijay

需要安装的包

模块:

loader:

plugins:

yarn install webpack webpack-cli webpack-dev-server style-loader css-loader sass-loader node-sass html-webpack-plugin clean-webpack-plugin extract-text-webpack-plugin -D

webpack.config.js

const path = require('path')
const webpack = require('webpack')
const htmlplugin = require('html-webpack-plugin')
const cleanplugin = require('clean-webpack-plugin')

module.exports = {
  mode: 'development',
  entry: './src/index.js',
  output: {
    filename: '[hash:4]-boundle.js',
    path: path.join(__dirname, 'dist')
  },
  module: {
    rules: [
      {
        test: /\.scss$/,
        use: ['style-loader', 'css-loader', 'sass-loader']
      },
      {
        test: /\.(jpg|png|gif|svg|webp)$/,
        use: ['file-loader']
      },
      {
        test: /\.(html|ejs)$/,
        use: ['html-loader']
      }
    ]
  },
  devServer: {
    contentBase: path.join(__dirname, 'dist'),
    port: 3000,
    historyApiFallback: true,
    overlay: true,
    hot: true
  },
  devtool: 'inline-source-map',
  plugins: [
    new cleanplugin(),
    new htmlplugin({
      template: path.join(__dirname, 'src', 'template.ejs'),
      title: 'hello sass'
    })
  ]
}

package.json

"scripts": {
    "build": "webpack",
    "build:prod": "webpack --production",
    "start": "webpack-dev-server"
  }
上一篇 下一篇

猜你喜欢

热点阅读