var-loader

string variable replace loader for webpack

Usage no npm install needed!

<script type="module">
  import varLoader from 'https://cdn.skypack.dev/var-loader';
</script>

README

var-loader

string variable replace loader for webpack

Installation

npm

$ npm install var-loader

or yarn

$ yarn add var-loader

Usage

// webpack.config.js
module.exports = {
    ...
    module: {
        rules: [{
            test: /\.tpl$/,
            use: [
                'raw-loader',
                {
                    loader: 'var-loader',
                    options: {

                        // the string will to replaced as regexp
                        find: /\$\{(.*?)\}/g

                        // the replace function as a value to return
                        replace: (key, val) => ['prefix', key, val].join('-'),

                        // the replace variable map
                        data: {
                            name: 'value'
                        }
                    }
                }
            ]
        }]
    }
};