placeholder-loader
v2.0.1
Published
webpack loader
Downloads
183
Readme
placeholder-loader
webpack loader
Replace placeholder in source with value returned by handler
Parameters
source
string
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