placeholder-loader

2.0.1 • Public • Published

placeholder-loader

webpack loader

Replace placeholder in source with value returned by handler

Parameters

Examples

// Loader options have been passed as an object
// *** in webpack.config.js ***
function handler() {
  console.dir(arguments, {colors: true, depth: null});
  console.dir(this, {colors: true, depth: null});
  // Do something
};
 
const webpackConfig = {
  module: {
    rules: [{
      test: /\.(js|jsx|ts)$/,
      use: [{
          loader: 'placeholder-loader',
            options: {
              placeholder: 'any_string_here',
              handler
          }
      }],
    }],
  },
}
 
// Loader options have been passed as a query string
// In case option `handler` is a string, loader looking for a file with appropriate name and 'require' it'.
// *** handler.js ***
module.exports = function() {
  // Do something
}
 
// *** in webpack.config.js ***
const webpackConfig = {
  module: {
    rules: [{
      test: /\.(js|vue|jsx|ts)$/,
      use: [
        'placeholder-loader?placeholder=any_string_here&handler=handlerPath'
      ],
    }],
  },
}
 
// Usage with the vue-loader
const webpackConfig = {
  module: {
    rules: [{
    test: /\.vue$/,
      use: [{
        loader: 'vue-loader',
        options : {
          preLoaders: {
            js: 'placeholder-loader?placeholder=any_string_here&handler=handlerPath'
          }
         }
       }
     ]
    }],
  },
}

Returns string source with placeholder replaced by value returned by handler

placeholder

string placed in source

Package Sidebar

Install

npm i placeholder-loader

Weekly Downloads

31

Version

2.0.1

License

ISC

Unpacked Size

10.8 kB

Total Files

16

Last publish

Collaborators

  • a.chepugov