S
S
StroevD2019-09-24 16:10:21
webpack
StroevD, 2019-09-24 16:10:21

How to change MiniCssExtractPlugin plugin output directory for Webpack?

I have the following webpack config:

const path = require('path')
const HTMLPlugin = require('html-webpack-plugin')
const BrowserSyncPlugin = require('browser-sync-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')

module.exports = {
  entry: './app/index.js',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist')
  },
  module: {
    rules: [
      {
        test: /\.pug$/,
        loader: 'pug-loader',
        options: {
          pretty: true
        }
      },
      {
        test: /\.s[ac]ss$/,
        use: [
          MiniCssExtractPlugin.loader,
          'css-loader',
          'sass-loader',
        ],
      },
    ]
  },
  plugins: [
    new HTMLPlugin({
      filename: 'index.html',
      template: './app/index.pug'
    }),
    new BrowserSyncPlugin({
      host: 'localhost',
      port: 3000,
      server: { baseDir: ['dist'] }
    }),
    new MiniCssExtractPlugin({
      filename: 'style.css',
    }),
  ]
};

Compiled from sass to css, the file ends up in the dist folder. How to change output directory for MiniCssExtractPlugin from dist to dist/css?
Tried changing filename: 'style.css' to 'css/style.css', './css/style.css', doesn't help

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Mes, 2020-11-05
@Segyus

new MiniCssExtractPlugin({
      filename: "styles/[name].css",
      chunkFilename: "styles/[id].css",
    }),

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question