GithubHelp home page GithubHelp logo

Comments (10)

davemcorwin avatar davemcorwin commented on June 12, 2024 1

looks good, thanks for looking into this!

from css-loader-minify-class.

odensc avatar odensc commented on June 12, 2024

Hey @davemcorwin, I can't seem to reproduce this. Let me know if you get an example working. :)

from css-loader-minify-class.

davemcorwin avatar davemcorwin commented on June 12, 2024

@odensc I pushed up an example showing the issue here

Please take a look if you can, perhaps I'm doing something wrong.

Thanks!

the gist is:

// styles1.css
.hello-world {
  color: blue;
}

// styles2.css
.goodbye-world {
  composes: hello-world from './styles1.css'
}

// index.js
import styles from './styles2.css'

function component() {
  const element = document.createElement('div')
  const classList = styles.goodbyeWorld.split(' ').map(c => `<li>${c}</li>`).join('')
  const html = `
    <div>
      classnames
      <ul>
        ${classList}
      </ul>
    </div>
  `
  element.innerHTML = html
  return element
}

document.body.appendChild((component()))

Perhaps there is a clue in the webpack output?

$ webpack
Hash: d0318d4811cfa32dfe33
Version: webpack 3.3.0
Time: 1655ms
     Asset      Size  Chunks             Chunk Names
 bundle.js   3.44 kB       0  [emitted]  main
styles.css  40 bytes       0  [emitted]  main
   [0] ./src/index.js 388 bytes {0} [built]
   [1] ./src/styles2.css 156 bytes {0} [built]
   [2] ./node_modules/css-loader?{"minimize":true,"modules":true,"camelCase":true,"localIdentName":"[name]__[local]--[hash:base64:5]"}!./src/styles2.css 835 bytes [built]
   [4] ./node_modules/css-loader?{"minimize":true,"modules":true,"camelCase":true,"localIdentName":"[name]__[local]--[hash:base64:5]"}!./src/styles1.css 316 bytes [built]
    + 3 hidden modules
Child extract-text-webpack-plugin /Users/dcorwin/Projects/cssm-test/node_modules/extract-text-webpack-plugin/dist /Users/dcorwin/Projects/cssm-test/node_modules/css-loader/index.js??ref--1-2!/Users/dcorwin/Projects/cssm-test/src/styles2.css:
       [0] ./node_modules/css-loader?{"minimize":true,"modules":true,"camelCase":true,"localIdentName":"[name]__[local]--[hash:base64:5]"}!./src/styles1.css 316 bytes {0} [built]
       [2] ./node_modules/css-loader?{"minimize":true,"modules":true,"camelCase":true,"localIdentName":"[name]__[local]--[hash:base64:5]"}!./src/styles2.css 835 bytes {0} [built]
        + 1 hidden module
✨  Done in 2.75s.

from css-loader-minify-class.

davemcorwin avatar davemcorwin commented on June 12, 2024

and the webpack config

const path = require('path')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const createMinifier = require('css-loader-minify-class')

module.exports = {
  entry: './src/index.js',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist')
  },
  module: {
    rules: [
      { test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/ },
      {
        test: /\.css$/,
        use: ExtractTextPlugin.extract({
          fallback: require.resolve('style-loader'),
          use: {
            loader: require.resolve('css-loader'),
            options: {
              minimize: true,
              modules: true,
              camelCase: true,
              localIdentName: '[name]__[local]--[hash:base64:5]',
              getLocalIdent: createMinifier(),
            },
          },
        })
      }
    ]
  },
  plugins: [
    new ExtractTextPlugin('styles.css'),
  ]
}

from css-loader-minify-class.

davemcorwin avatar davemcorwin commented on June 12, 2024

it looks like the classes in the output are NOT modified as well. I don't the issue is really in this repo, i don't think the classes are even being seen.

from css-loader-minify-class.

davemcorwin avatar davemcorwin commented on June 12, 2024

closing, this is a css-loader issue. webpack-contrib/css-loader#524

from css-loader-minify-class.

odensc avatar odensc commented on June 12, 2024

In the meantime, I made something hacky that works. Try this:

const path = require('path')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const { Minifier } = require('css-loader-minify-class')

module.exports = {
  entry: './src/index.js',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist')
  },
  module: {
    rules: [
      { test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/ },
      {
        test: /\.css$/,
        use: ExtractTextPlugin.extract({
          fallback: require.resolve('style-loader'),
          use: {
            loader: require.resolve('css-loader'),
            options: {
              minimize: true,
              modules: true,
              camelCase: true,
              localIdentName: '[minify][local]',
            },
          },
        })
      }
    ]
  },
  plugins: [
    new ExtractTextPlugin('styles.css'),
  ]
}

const minifier = new Minifier();
Object.defineProperty(module.exports, 'customInterpolateName', {
  enumerable: false,
  value: function(url) {
    if (url.includes('[minify]')) {
      const localName = url.replace('[minify]', '');
      return minifier.getLocalIdent(this, null, localName);
    }
  }
})

from css-loader-minify-class.

davemcorwin avatar davemcorwin commented on June 12, 2024

from css-loader-minify-class.

odensc avatar odensc commented on June 12, 2024

:D Not the most ideal solution but it works until css-loader is fixed.

I'll see if they'll accept a PR to fix it - if not, I'll add something like this into the module.

from css-loader-minify-class.

odensc avatar odensc commented on June 12, 2024

Hey @davemcorwin, according to webpack-contrib/css-loader#583 (comment) - adding ident: "css" to the options should fix this. Let me know if it works and I'll close this.

from css-loader-minify-class.

Related Issues (3)

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.