├── .gitignore ├── index.js ├── package.json ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | package-lock.json 3 | 4 | # Editor 5 | .idea 6 | .vscode -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const UNICODE_MATCH_REG = /[^\x00-\xff]/g; 2 | const CONTENT_MATCH_REG = /(? { 17 | const sassLoader = require.resolve('sass-loader'); 18 | config.module.rules.filter(rule => { 19 | return rule.test.toString().indexOf("scss") !== -1; 20 | }) 21 | .forEach(rule => { 22 | rule.oneOf.forEach(oneOfRule => { 23 | const sassLoaderIndex = oneOfRule.use.findIndex(item => item.loader === sassLoader); 24 | oneOfRule.use.splice(sassLoaderIndex, 0, 25 | { loader: require.resolve("css-unicode-loader") }); 26 | }); 27 | }); 28 | } 29 | } 30 | ``` 31 | 32 | if use webpack.config.js, add the loader in the config file . 33 | 34 | ```js 35 | // webpack.config.js 36 | module.exports = { 37 | ... 38 | module: { 39 | rules: [{ 40 | test: /\.scss$/, 41 | use: [{ 42 | loader: "style-loader" // Creates `style` nodes from JS strings 43 | }, { 44 | loader: "css-loader" // Translates CSS into CommonJS 45 | }, { 46 | loader: "css-unicode-loader" // Convert double-byte character to unicode encoding. 47 | }, { 48 | loader: "sass-loader" // Compiles Sass to CSS 49 | }] 50 | }] 51 | } 52 | }; 53 | ``` 54 | 55 | ## Note 56 | 57 | This loader must be before sass-loader if you used sass-loader 58 | 59 | ## Example 60 | 61 | ```css 62 | .scss::after { 63 | content: "中国"; 64 | } 65 | .icon-content::after { 66 | content: ""; 67 | } 68 | ``` 69 | 70 | after loader handle 71 | 72 | ```css 73 | .scss::after { 74 | content: "\4e2d\56fd"; 75 | } 76 | .icon-content::after { 77 | content: "\e6df"; 78 | } 79 | ``` 80 | --------------------------------------------------------------------------------