Reputation: 227
On my local environment, unicode characters work fine but when I run webpack to bundle and deploy, string which is like "\uf00c" becomes "" in index_bundle.js
I think there's a problem in babel config or webpack config but I can't resolve it as I'm new to the whole stack.
Here is the codes:
<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>
My .babelrc:
{
"presets": [
["env"], ["react"]
],
"plugins": ["transform-class-properties", "transform-object-rest-spread"]
}
And my 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;
Upvotes: 3
Views: 4534
Reputation: 1483
I found the solution. You need to set your javascript file UTF-8
. You could either do
<script type="text/javascript" charset="UTF-8" src="xyz.js"></script>
or
<head>
...
<meta charset="UTF-8">
...
</head>
for all your HTML files
See https://stackoverflow.com/a/44907641/2075423
Upvotes: 10