From 18b809b1d15a03cc469e6dd31b17fa277cdb76bd Mon Sep 17 00:00:00 2001 From: Jason Quense Date: Thu, 19 May 2022 08:21:47 -0400 Subject: [PATCH] feat: enable toggling message extraction --- packages/babel-preset/index.js | 5 +++++ packages/babel-preset/intl-preset.js | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/babel-preset/index.js b/packages/babel-preset/index.js index cf35e360..86fee469 100644 --- a/packages/babel-preset/index.js +++ b/packages/babel-preset/index.js @@ -229,6 +229,11 @@ function preset(api, explicitOptions = {}) { messagesDir: 'build/messages', }; + // unless explict, don't extract messages in dev mode + if (development && intlOpts.extractMessages == null) { + intlOpts.extractMessages = false; + } + presets.push([intlPreset, intlOpts]); } diff --git a/packages/babel-preset/intl-preset.js b/packages/babel-preset/intl-preset.js index 36bc61bd..b86d3af3 100644 --- a/packages/babel-preset/intl-preset.js +++ b/packages/babel-preset/intl-preset.js @@ -10,6 +10,7 @@ module.exports = function intlPreset(_, options = {}) { messagesDir, prefix, idInterpolationPattern = '[sha512:contenthash:base64:6]', + extractMessages = true, ...rest } = options; @@ -40,7 +41,7 @@ module.exports = function intlPreset(_, options = {}) { overrideIdFn, ...rest, onMsgExtracted(filename, messages) { - if (!messages?.length) return; + if (!messages?.length || !extractMessages) return; if (!filename.startsWith(workspaceRoot)) { throw new Error(