webpack-encoding-plugin

0.3.1 • Public • Published

Build Status

Webpack Encoding Plugin

Take control over the encoding of emitted webpack assets. This can be useful, if the delivering webserver enforces a specific content-type, so that your js-code is not interpreted as utf-8 by the browser.

Usage

install module

npm install webpack-encoding-plugin

setup webpack config

const EncodingPlugin = require('webpack-encoding-plugin');
module.exports = {
    entry: './entry.js',
    output: {
        path: '../dist',
        filename: 'bundle.js'
    },
    plugins: [new EncodingPlugin({
        encoding: 'iso-8859-1'
    })]
};

Additional options:

test, include, exclude RegExp or array of RegExps to filter processed files (default test is /(\.js|\.css)($|\?)/i)

Encodings

The Plugin uses iconv-lite to handle the encoding. A list of supported encodings can be found here

webpack-dev-server

To use non-utf-8 encoding with webpack-dev-server, you must set the appropriate charset like so:

devServer:  {
   headers: {
      'Access-Control-Allow-Origin': '*',
      'Content-Type': 'application/javascript; charset=windows-1251'
   }
   // ...
}

Readme

Keywords

Package Sidebar

Install

npm i webpack-encoding-plugin

Weekly Downloads

1,272

Version

0.3.1

License

MIT

Unpacked Size

6.66 kB

Total Files

8

Last publish

Collaborators

  • quackes