简体   繁体   中英

webpack 4 - “normal”, nicely formatted CSS output possible?

I try to use webpack 4 for a - what initially seemed to me - simple task: generate all the possible CSS a SCSS framework could potentially produce and output it as a nicely formatted CSS file. While a gulp setup did the job in 5 minutes:.

// Gulp
let gulp = require('gulp')
let gulpScss = require('gulp-sass')
let postcss = require("gulp-postcss")
let autoprefixer = require("autoprefixer")

function style() {
  return (
    gulp
      .src('src/scss/main.scss')
      .pipe(gulpScss())
      .on("error", gulpScss.logError)
      .pipe(postcss([autoprefixer()]))
      .pipe(gulp.dest('dist'))
  );
}
exports.style = style;

.. .I am still struggling with webpack 4:

// webpack 4
const path = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const ExtractTextPlugin = require("extract-text-webpack-plugin")
const autoprefixer = require('autoprefixer')

const isDevelopment = process.env.NODE_ENV !== 'production'
const rootPath = path.resolve(__dirname, '../')

module.exports = {
  entry: { bundle: './src/app.js' },
  output: { [...] },
  module: {
    rules: [ {
        test: /\.js$/,
        [...]
      }, {
        test: /\.(scss|css)$/,
        use: [
          use: ExtractTextPlugin.extract({
            fallback: "style-loader",
            use: ['css-loader', 'sass-loader']
          })
        ]
      }
    ]
  },
  plugins: [
    new HtmlWebpackPlugin({ [...] }),
    new ExtractTextPlugin("inuitcss.css")
  ]
}

// NPM
"build": "webpack -p --progress --mode production --config ./config/build.js"

I also worked through some posts here on stackoverflow, namely this one: Sass loader and webpack 4 and others, but they all use mini-css-extract-plugin or the extract-text-plugin.

The thing is: I DO get results, this is not the problem; the problem is, that they are all minified.

My question: Is it at all possible to generate non-minified CSS output with webpack 4, possibly with such nice configuration options like "nested" etc?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM