styzhang / css-unicode-loader Goto Github PK
View Code? Open in Web Editor NEWwebpack loader for convert chinese or double-byte character string of scss/sass/less/css files to unicode encoding.
License: MIT License
webpack loader for convert chinese or double-byte character string of scss/sass/less/css files to unicode encoding.
License: MIT License
我在使用的时候, 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") });
});
});
}
}
如题
vue-cli@5怎么配置,一直都是无效的
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'
)}`
}
}
},
}
Ï
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.