Skip to content

Instantly share code, notes, and snippets.

@mzgoddard
Last active October 1, 2015 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mzgoddard/8357e6746e0f9fc57a88 to your computer and use it in GitHub Desktop.
Save mzgoddard/8357e6746e0f9fc57a88 to your computer and use it in GitHub Desktop.
Example custom lodash initialization loader
// web_loaders/lodash-init-loader.js
// example way to create a custom loader to modify
module.exports = function(source) {
return source + [
'',
'module.exports = (',
'this.options.lodashInit.toString().split('\n'),',
')(_);',
].join('\n');
};
module.exports = {
// ...
module: {
loaders: [
{
test: /lodash/,
loaders: ['lodash-init', 'exports?_']
}
],
},
lodashInit: function(_) {
_.templateSettings = {
evaluate: /\{\{(.+?)\}\}/g,
escape: /\{\{=(.+?)\}\}/g,
interpolate: /\{\{-(.+?)\}\}/g
};
return _;
},
// ...
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment