1. decoded-text-loader
A Webpack loader to convert files on disk(in any encoding) into a JavaScript UTF-8 string
decoded-text-loader
Package: decoded-text-loader
Created by: leesdolphin
Last modified: Thu, 28 Apr 2022 08:07:28 GMT
Version: 1.0.0
License: MIT
Downloads: 14
Repository: https://github.com/leesdolphin/decoded-text-loader

Install

npm install decoded-text-loader
yarn add decoded-text-loader

decoded-text-loader

A webpack loader to convert text of an unknown encoding into a JavaScript UTF-8 string

Note: This does not produce an webpack-suitable output. This loader must be chained onto another loader which outputs
valid JavaScript.

To install

npm install --save-dev decoded-text-loader

To use in webpack

webpack.config.js

module.exports = {
  module: {
    loaders: [
      {
        test: /_large\.txt$/,
        use: [
          {
            loader: 'file-loader',
            options: {},
          },
          { loader: 'decoded-text-loader' },
        ],
      },
      {
        test: /\.txt$/,
        use: [
          { loader: 'raw-loader' },
          { loader: 'decoded-text-loader' },
        ],
      },
    ],
  },
};

This will automatically convert any *_large.txt to use the
file-loader so they can be
loaded dynamically. All other *.txt files will be loaded using
raw-loader so they can be
accessed directly.

Caution: webpack loaders are executed in the reverse order to their declaration so whilst the order here looks weird, it is correct.

Notes

webpack handles loading the files into a string for this loader to consume;
that string is inspected using
jschardet, and then converted
into the detected encoding using
text-encoding.

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin