Giter Site home page Giter Site logo

css-unicode-loader's People

Contributors

styzhang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

css-unicode-loader's Issues

vue-cli4 搭建的项目按照文档提示设置无效

const path = require('path')
const CompressionWebpackPlugin = require('compression-webpack-plugin')

const resolve = dir => path.resolve(__dirname, dir)
const productConfig = require('./src/version/config')
const isProd = process.env.NODE_ENV === 'production'

module.exports = {
publicPath: '/', // vue-cli3.3+,部署应用包时的基本 URL,用法和 webpack 本身的 output.publicPath 一致
assetsDir: 'static', // 静态资源地址
productionSourceMap: false,
transpileDependencies: ['view-design', 'crypto-js'], // 解决在 ie 上无法访问的问题
// scss 全局引入
css: {
extract: isProd, // 开发环境下关闭,true 和热更新不兼容,保证 css 热更新
sourceMap: !isProd,
loaderOptions: {
sass: {
// implementation: require('sass'),
additionalData: @import "@/styles/common/_variables.scss"; @import "@/styles/common/_mixins.scss";,
},
},
},
chainWebpack: config => {
// 修复HMR
config.resolve.symlinks(true)

	// 根据 js 版本配置文件修改 index.html 文件中的产品名称
	config.plugin('html').tap(options => {
		options[0].title = productConfig.productName.join('')

		return options
	})

	return config
},
// 配置 webpack
configureWebpack: config => {
	// 路径别名
	config.resolve.alias = {
		...config.resolve.alias,
		'@assets': resolve('src/assets'),
		'@styles': resolve('src/styles'),
		'@services': resolve('src/services'),
		'@router': resolve('src/router'),
		'@store': resolve('src/store'),
		'@components': resolve('src/components'),
		'@views': resolve('src/views'),
		'@scripts': resolve('src/scripts'),
		'@constants': resolve('src/constants'),
		'@mixins': resolve('src/scripts/mixins'),
		'@utils': resolve('src/scripts/utils'),
	}
	const sassLoader = require.resolve('sass-loader')

	config.module.rules
		.filter(rule => {
			return rule.test.toString().indexOf('scss') !== -1
		})
		.forEach(rule => {
			rule.oneOf.forEach(oneOfRule => {
				const sassLoaderIndex = oneOfRule.use.findIndex(
					item => item.loader === sassLoader
				)
				oneOfRule.use.splice(sassLoaderIndex, 0, {
					loader: require.resolve('css-unicode-loader'),
				})
			})
		})
	// 添加对 pdf 文件的处理 loader
	console.log(config.module.rules)
	config.module.rules = [
		...config.module.rules,
		{
			test: /\.pdf$/,
			use: 'url-loader',
		},
		{
			test: /\.scss$/,
			use: [
				{
					loader: 'css-unicode-loader', // Convert double-byte character to unicode encoding.
				},
				{
					loader: 'sass-loader', // Compiles Sass to CSS
				},
			],
		},
	]

	// gzip 压缩
	if (isProd) {
		config.plugins = [
			...config.plugins,
			new CompressionWebpackPlugin({
				filename: '[path][base].gz',
				algorithm: 'gzip',
				test: /\.(js|css|html|svg)(\?.*)?$/i,
				threshold: 10240,
				minRatio: 0.8,
			}),
		]
	} else {
		// 生成可调试的代码
		config.output.devtoolModuleFilenameTemplate = info => {
			const resPath = info.resourcePath

			if (
				(/\.vue$/.test(resPath) &&
					!/type=script/.test(info.identifier)) ||
				/node_modules/.test(resPath)
			) {
				return `webpack:///${resPath}?${info.hash}`
			}
			return `webpack:///${resPath.replace(
				'./src',
				'uncompiled-code/src'
			)}`
		}
	}
},

}
Ï

rule 可能不存在test字段

我在使用的时候, vue-cli项目, 发现config.module.rules里面有一项内容不存在test字段, 所以可以先判断有没有test字段 (为了加粗显示, 就没有使用代码块了, 直接用的文本)

// vue.config.js
module.exports = {
configureWebpack: config => {
const sassLoader = require.resolve('sass-loader');
config.module.rules.filter(rule => {
return **rule.test** && rule.test.toString().indexOf("scss") !== -1;
})
.forEach(rule => {
rule.oneOf.forEach(oneOfRule => {
const sassLoaderIndex = oneOfRule.use.findIndex(item => item.loader === sassLoader);
oneOfRule.use.splice(sassLoaderIndex, 0,
{ loader: require.resolve("css-unicode-loader") });
});
});
}
}

你好,想问一下乱码问题的原因是sass-loader的问题吗?感谢!

环境:node16 + @vue/cli4 + elementUI2.15.7 + sass 1.43.4 + sass-loader 10.1.1
该环境中打包之后会出现 el-icon css乱码:
image

但是同样的版本使用vitejs构建的项目就正常,当然vitejs不需要手动引入:sass-loader。

使用了大佬的这个loader确实解决了,想了解一下深层原因,请教一下

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.