Giter Club home page Giter Club logo

Comments (4)

eliperelman avatar eliperelman commented on August 11, 2024

Interesting, I hadn't noticed this particular use case. I think we can find a way to make this work.

So, there is no .use method from a Rule instance. There is a loader method which has the signature:

loader(name, loader, options)

According to the Webpack docs a UseEntry must have a loader property which is a string. If I execute the extract method, let's look at the return:

> ExtractTextPlugin.extract({ fallback: 'style-loader', use: 'css-loader' })
[ { loader: '/temp/node_modules/extract-text-webpack-plugin/loader.js',
    options: { omit: 1, remove: true } },
  { loader: 'style-loader' },
  { loader: 'css-loader' } ]

So, looks like 3 loaders with possible options. Since webpack-chain requires loaders to be named, you can get around this by using an index or something to generate that name (or by using the loader itself as the ID):

const rule = config.module.rule('css');

ExtractTextPlugin
  .extract({ fallback: 'style-loader', use: 'css-loader' })
  .map(({ loader, options }, index) => rule.loader(index, loader, options));

Will that work for you?

from webpack-chain.

sean-clayton avatar sean-clayton commented on August 11, 2024

@eliperelman Unfortunately not :( I don't think it's an issue with webpack-chain at this point, though, so I'm going to go ahead and close the ticket—thank you for the help, though 😄

from webpack-chain.

eliperelman avatar eliperelman commented on August 11, 2024

@sean-clayton ah ok. Please let me know if you find out what the issue was, and if you think there is something actionable we can do here. Thanks!

from webpack-chain.

sean-clayton avatar sean-clayton commented on August 11, 2024

@eliperelman I did a little more messing around and I got a build to successfully output a CSS file via the extract plugin, but it looks like css-loader doesn't take effect (I have minimize set to true, but the extracted CSS is not minimized).

I've created a repo here: https://github.com/sean-clayton/neutrino-test

The steps to reproduce are:

  • Install deps: yarn install
  • Run build: yarn build

Again, I'm not sure this is a problem with webpack-chain.

Here is the error I'm getting:

./~/css-loader?{"minimize":true}!./~/extract-text-webpack-plugin/loader.js?{"omit":1,"remove":true}!./~/style-loader!./~/css-loader?{"minimize":true}!./~/normalize.css/normalize.css
Module build failed: Unknown word (5:1)

  3 | // load the styles
  4 | var content = require("!!../css-loader/index.js?{\"minimize\":true}!./normalize.css");
> 5 | if(typeof content === 'string') content = [[module.id, content, '']];
    | ^
  6 | // add the styles to the DOM
  7 | var update = require("!../style-loader/addStyles.js")(content, {});
  8 | if(content.locals) module.exports = content.locals;

Error
    at /Users/sean/code/neutrino-test/node_modules/css-loader/lib/processCss.js:214:23
    at runMicrotasksCallback (internal/process/next_tick.js:58:5)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)
 @ ./~/normalize.css/normalize.css 4:14-184
 @ ./src/index.js
 @ multi ./src/index.js
./~/css-loader?{"minimize":true}!./~/extract-text-webpack-plugin/loader.js?{"omit":1,"remove":true}!./~/style-loader!./~/css-loader?{"minimize":true}!./~/normalize.css/normalize.css
Module build failed: Unknown word (1:1)

> 1 | // removed by extract-text-webpack-plugin
    | ^

Error
    at /Users/sean/code/neutrino-test/node_modules/css-loader/lib/processCss.js:214:23
    at runMicrotasksCallback (internal/process/next_tick.js:58:5)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)

from webpack-chain.

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.