gpt4 book ai didi

reactjs - 使用 webpack 和 babel 捆绑和部署 React 应用程序时未显示 Unicode 字符

转载 作者:行者123 更新时间:2023-12-05 01:00:32 27 4
gpt4 key购买 nike

在我的本地环境中,unicode 字符可以正常工作,但是当我运行 webpack 进行捆绑和部署时,类似 "\uf00c"的字符串在 index_bundle.js 中变成了 ""

我认为 babel 配置或 webpack 配置存在问题,但我无法解决,因为我是整个堆栈的新手。

代码如下:

<Label className="switch switch-icon switch-pill switch-success">
<Input type="checkbox" className="switch-input" defaultChecked onChange={this.handleActivateUser.bind(this, user.id)}/>
<span className="switch-label" data-on={'\uf00c'} data-off={'\uf00d'}></span>
<span className="switch-handle"></span>
</Label>

我的.babelrc:

{
"presets": [
["env"], ["react"]
],
"plugins": ["transform-class-properties", "transform-object-rest-spread"]
}

还有我的 webpack.config.js:

var path = require('path');
var HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const extractCSS = new ExtractTextPlugin('[name].fonts.css');
const extractSCSS = new ExtractTextPlugin('[name].styles.css');
const webpackUglifyJsPlugin = require('webpack-uglify-js-plugin');
var webpack = require('webpack');
config = {
entry: ['babel-polyfill', 'whatwg-fetch', './app/index.js'],
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'index_bundle.js',
publicPath: '/'
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: 'babel-loader'
},
{
test: /\.(scss)$/,
use: ['css-hot-loader'].concat(extractSCSS.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {alias: {'../img': '../public/img'}}
},
{
loader: 'sass-loader'
}
]
}))
},
{
test: /\.css$/,
use: extractCSS.extract({
fallback: 'style-loader',
use: 'css-loader'
})
},
{
test: /\.(png|jpg|jpeg|gif|ico)$/,
use: [
{
// loader: 'url-loader'
loader: 'file-loader',
options: {
name: './img/[name].[hash].[ext]'
}
}
]
},
{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
// loader: 'url-loader'
loader: 'file-loader',
options: {
name: './fonts/[name].[hash].[ext]'
}
}
]
}
]
},
devServer: {
historyApiFallback: true
},
plugins: [
new HtmlWebpackPlugin({
template: 'app/index.html'
}),
extractCSS,
extractSCSS,
new CopyWebpackPlugin([
{from: './public/img', to: 'img'}
],
{copyUnmodified: false}
)
]
}
module.exports = config;

最佳答案

我找到了解决方案。您需要设置您的 javascript 文件 UTF-8。你可以这样做

<script type="text/javascript" charset="UTF-8" src="xyz.js"></script>

<head>
...
<meta charset="UTF-8">
...
</head>

所有 HTML 文件

https://stackoverflow.com/a/44907641/2075423

关于reactjs - 使用 webpack 和 babel 捆绑和部署 React 应用程序时未显示 Unicode 字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49064060/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com