美文网首页
Sass热更新webpack配置

Sass热更新webpack配置

作者: Yokiijay | 来源:发表于2019-05-09 10:38 被阅读0次

需要安装的包

模块:

  • webpack
  • webpack-cli
  • webpack-dev-server
  • node-sass

loader:

  • style-loader 用作fallback
  • css-loader
  • sass-loader
  • file-loader 解决js css引入图片问题
  • html-loader 解决html引入图片问题

plugins:

  • html-webpack-plugin 将html也打包
  • clean-webpack-plugin
  • extract-text-webpack-plugin
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"
  }

相关文章

  • Sass热更新webpack配置

    需要安装的包 模块: webpack webpack-cli webpack-dev-server node-sa...

  • 2019-03-14

    成功搭建的webpack和sass的配置,实现了实时更新css文件,然后愉快的使用sass编写样式。 正在完成编辑...

  • webpack

    // webpack配置chainWebpack: config => {// 热更新 修复HMRconfig.r...

  • webpack项目引入sass模块

    webpack引入sass模块 webpack管理的项目,我们希望用sass定义样式,为了正常编译,需要做如下配置...

  • webpack热更新配置

    1. 安装 react-hot-loader 2. webpack配置 3. babelrc 注意:配置到默认开发...

  • Vue中配置sass

    1、安装sass 2、在webpack.base.conf.js里添加配置 3、使用sass

  • create-react-app 配置 sass

    一。配置webpack文件1.npm install sass-loader node-sass --save-d...

  • webpack devServer 相关配置

    1、webpack devServer 开启服务的简单配置 2、模块热更新 plugins 依赖配置 3、利用 b...

  • sass使用总结

    1、安装sass、sass-loader 2、配置webpack.base.conf.js 3、在组件中使用 运行...

  • 使用webpack配置热更新

    步骤: 安装webpack、webpack-cli、webpack-dev-server、html-webpack...

网友评论

      本文标题:Sass热更新webpack配置

      本文链接:https://www.haomeiwen.com/subject/ubjioqtx.html