From f7743370134da579c8d38116ab6e5f74e98b9151 Mon Sep 17 00:00:00 2001 From: Jan Nicklas Date: Sun, 7 Jul 2019 23:51:38 +0200 Subject: [PATCH] fix: Prevent lodash from being inlined to work around a babel-loader incompatibility fix #1223 --- lib/loader.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/loader.js b/lib/loader.js index 01c52cd9..cbc6e536 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -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 + ')();' +