Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape Characters in CSS content not processed correctly #459

Closed
rjnair-nm opened this issue Mar 17, 2017 · 12 comments
Closed

Escape Characters in CSS content not processed correctly #459

rjnair-nm opened this issue Mar 17, 2017 · 12 comments
Assignees

Comments

@rjnair-nm
Copy link

I am using css-loader and i could see that the content is not being processed correctly.

Original CSS :-

.icon-caret-left:before {
   content: “\F10C"
}

The above CSS was processed by webpack to :-

.icon-caret-left:before {
   content: '"\\f10c"'
}

Webpack: 2.2.1
CSS-Loader: 0.27.3
Node: 7.2.1

@michael-ciniawsky
Copy link
Member

@rjnair-nm for getting started did an earlier version of css-loader process it correctly? 😛

@rjnair-nm
Copy link
Author

@michael-ciniawsky I had tried using css-loader 0.25.0 with webpack 1 and that used to work fine. I was upgrading to webpack 2 and while using the latest version of css-loader with that, i came across this issue.

@michael-ciniawsky
Copy link
Member

michael-ciniawsky commented Mar 17, 2017

@rjnair-nm While copy and paste, maybe typo while you opened the issue maybe the root cause 😆

.icon-caret-left:before {
   content: “\F10C"
}
content:  “<= \F10C"  //  “ => "

@michael-ciniawsky
Copy link
Member

michael-ciniawsky commented Mar 17, 2017

The delimiters don't match

@michael-ciniawsky
Copy link
Member

Otherwise I need webpack 1 && webpack 2 configs + ideally a small test repo for each to debug 😛

@rjnair-nm
Copy link
Author

@michael-ciniawsky I am using a custom library like Bootsrap which has the class definition as below :-

.icon-caret-left:before {
  content: "\f10c"; 
}

When the webpack processes this via css-loader, it transforms to : -

.icon-caret-left:before {
   content: '"\\f10c"'
}

Webpack rule for css :-

const styleLoaders = ['css-loader?minimize&sourceMap&importLoaders=5', 'postcss-loader', 'sass-loader?sourceMap'];

{
              test: /.s?css$/,
              include: [path.join(root, 'src/client'), path.resolve(root, 'node_modules')],
              loader: IS_DEV ? 'style-loader!' + styleLoaders.join('!') : ExtractTextPlugin.extract({ fallback: 'style-loader', use: styleLoaders })
 }

I see this issue #87 which was raised here. But in that case it was removing the escape characters, but in my case its adding extra escape characters 😄

@michael-ciniawsky
Copy link
Member

kk, as a 'workaround' would it be possible to reference bootstrap as static asset in meantime and exclude it from the bundle ? Also could you test another decl if it happens there also and a maybe pattern comes up when and where 😛 ?

@alexander-akait
Copy link
Member

@rjnair-nm added tests #493, seems for one escaped characters all works fine, maybe problems in some postcss plugin? Can you create minimal reproduce repo?

@zaneadix
Copy link

zaneadix commented Jul 27, 2017

I'm having this same issue without postcss. I'm running sass-loader right into css-loader and getting similar output.

.oui-icon-star.oui-icon-filled:before { content: '\e20c'; }

outputs as

.oui-icon-star.oui-icon-filled:before { content: "'\\e20c'"; }

{
            test: /\.scss$/,
            include: [globalStyleMain],
            use: ExtractTextPlugin.extract({
                fallback: 'style-loader',
                use: ['css-loader', sassLoader],
            })
        }
"devDependencies": {
    ...
    "css-loader": "0.28.4",
    ...
    "sass-loader": "^6.0.0",
    ...
    "webpack": "^3.4.1",
  }```

@zaneadix
Copy link

zaneadix commented Jul 28, 2017

For anyone still having this issue I've created a temporary fix locally using a custom loader.

resolveLoader: {
    alias: {
        'escape-content-cleanup-loader': helpers.root('loaders/escape-content-cleanup-loader.js')
    }
},
...
module: {
    rules: [{
        test: /\.scss$/,
        use: ['style-loader', 'escape-content-cleanup-loader', 'css-loader', sassLoader]
    }]
}

custom loader

module.exports = function(content) {
    content = content.replace(/\\"'\\+([a-zA-Z0-9]){4}'\\"/g, function(value) {
        return value.replace(/'/g, '').replace(/\\\\/, '');
    });
    return content;
}

This is most likely highly tailored to my specific situation but you should get the jist. Just use a simple custom loader to run some cleanup on the css-loader output for now.

@alexander-akait
Copy link
Member

Close in favor #578

joey-g pushed a commit to joey-g/prograde that referenced this issue Mar 14, 2018
…ling issues were around webpack defect webpack-contrib/css-loader#459. To temporarily get around this, I've moved all theme-specific styles/images into public directory as static resources and linked directly from <head>.
@Yaowenjie
Copy link

Yaowenjie commented May 29, 2018

@zaneadix I used your way to customize one loader for my issue, which is about a special character in css content (e.g. ü inside of content: 'something über'), and it works fine. Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants