GithubHelp home page GithubHelp logo

Comments (4)

denizguzel avatar denizguzel commented on August 12, 2024 2

I'm using this project because I need to extract the CSS as a file to pass it to a library that requires a CSS URL.

Is there any alternative to achieve this? Seems that css-loader is generating a JS file, so I can't use it as a resource directly. And I don't think that I can use mini-css-extract-plugin for this.

Edit:

Fixed by replacing css-loader > extract-loader by simply using postcss-loader.

Yeah I was using the css-loader and extract-loader too but it seems unnessesary. Below code just works fine without css-loader and extract-loader.

const postcssPresetEnv = require('postcss-preset-env');
const sass = require('sass');

{
  test: /\.(sass|scss)$/,
  use: [
    {
      loader: 'file-loader',
      options: {
        name: '[name].[contenthash].css',
      },
    },
    {
      loader: 'postcss-loader',
      options: {
        postcssOptions: {
          plugins: ['postcss-import', postcssPresetEnv()],
        },
      },
    },
    {
      loader: 'sass-loader',
      options: {
        // Prefer `dart-sass`
        implementation: sass,
        sourceMap: false,
        sassOptions: {
          includePaths: ['node_modules', 'apps', '.'],
        },
      },
    },
  ],
},
{
  test: /\.css$/,
  use: [
    {
      loader: 'file-loader',
      options: {
        name: '[name].[contenthash].css',
      },
    },
    {
      loader: 'postcss-loader',
      options: {
        postcssOptions: {
          plugins: ['postcss-import', postcssPresetEnv()],
        },
      },
    }
  ],
},

from extract-loader.

MaximeCheramy avatar MaximeCheramy commented on August 12, 2024

I'm using this project because I need to extract the CSS as a file to pass it to a library that requires a CSS URL.

Is there any alternative to achieve this? Seems that css-loader is generating a JS file, so I can't use it as a resource directly. And I don't think that I can use mini-css-extract-plugin for this.

Edit:

Fixed by replacing css-loader > extract-loader by simply using postcss-loader.

from extract-loader.

Mario-Eis avatar Mario-Eis commented on August 12, 2024

But postcss-loader doesn't seem to process url(...) as require/import. I have to load fonts in the css. And woff2 files need to be handled.

from extract-loader.

MaximeCheramy avatar MaximeCheramy commented on August 12, 2024

My config is that can help people:

 resourceQuery: /file/, // foo.css?file
        use: [{
          loader: 'postcss-loader',
          options: {
            postcssOptions: {
              plugins: [
                postcssUrl({ url: 'inline' })
              ]
            }
          }

from extract-loader.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.