Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Prevent lodash from being inlined to work around a babel-loader incompatibility #1239

Merged
merged 2 commits into from Jul 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
4 changes: 2 additions & 2 deletions spec/caching.spec.js
Expand Up @@ -202,7 +202,7 @@ describe('HtmlWebpackPluginCaching', () => {
.then(done);
});

it('should not slow down linear (15 plugins should not take twice as much time as a 1 plugin)', done => {
it('should not slow down linear (10 plugins should not take twice as much time as a 1 plugin)', done => {
const template = path.join(__dirname, 'fixtures/plain.html');
const createHtmlWebpackPlugin = () => new HtmlWebpackPlugin({
template: template
Expand All @@ -213,7 +213,7 @@ describe('HtmlWebpackPluginCaching', () => {
let multiCompileRunDuration;

let singleCompiler = setUpCompiler(createHtmlWebpackPlugin());
let multiCompiler = setUpCompiler.apply(null, Array(15).fill(0).map(() => createHtmlWebpackPlugin()));
let multiCompiler = setUpCompiler.apply(null, Array(10).fill(0).map(() => createHtmlWebpackPlugin()));

Promise.resolve()
.then(function singleCompileRun () {
Expand Down