Last active
October 1, 2015 15:15
-
-
Save mzgoddard/8357e6746e0f9fc57a88 to your computer and use it in GitHub Desktop.
Example custom lodash initialization loader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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'); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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