Skip to content

Commit

Permalink
fix: Prevent lodash from being inlined to work around a babel-loader …
Browse files Browse the repository at this point in the history
…incompatibility

fix #1223
  • Loading branch information
jantimon committed Jul 7, 2019
1 parent a18f809 commit f774337
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/loader.js
Expand Up @@ -24,8 +24,9 @@ module.exports = function (source) {
// The following part renders the template with lodash as aminimalistic loader
//
const template = _.template(source, _.defaults(options, { interpolate: /<%=([\s\S]+?)%>/g, variable: 'data' }));
// Require !!lodash - using !! will disable all loaders (e.g. babel)
return 'var _ = require(' + loaderUtils.stringifyRequest(this, '!!' + require.resolve('lodash')) + ');' +
// Use __non_webpack_require__ to enforce using the native nodejs require
// during template execution
return 'var _ = __non_webpack_require__(' + JSON.stringify(require.resolve('lodash')) + ');' +
'module.exports = function (templateParams) { with(templateParams) {' +
// Execute the lodash template
'return (' + template.source + ')();' +
Expand Down

0 comments on commit f774337

Please sign in to comment.