Chinese issues garbled after webpack packaged React project

problem:

React with the project after webpack packaged, deployed to the server, and then directly access the index.html file packaged, there have been Chinese garbled.

Solution:

When webpack packaging, using webpack-encoding-pluginplug-ins can be resolved. Steps are as follows:

The first step in installing webpack-encoding-plugin plugin

cnpm i webpack-encoding-plugin -D

The second step configuration file webpack.config.js

Add plug-in webpack.config.js file:

const EncodingPlugin = require('webpack-encoding-plugin');
module.exports = {
    // ......
    plugins: [
    new EncodingPlugin({
        encoding: 'UTF-8'
    })
    ]
}

After the completion of the operation, re-run packaging commands, files will not appear garbled.

Published 124 original articles · won praise 9 · views 20000 +

Guess you like

Origin blog.csdn.net/p445098355/article/details/104788658