Skip to content

Commit

Permalink
feat: enable toggling message extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense committed May 19, 2022
1 parent 6260cc3 commit 18b809b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/babel-preset/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

Expand Down
3 changes: 2 additions & 1 deletion packages/babel-preset/intl-preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = function intlPreset(_, options = {}) {
messagesDir,
prefix,
idInterpolationPattern = '[sha512:contenthash:base64:6]',
extractMessages = true,
...rest
} = options;

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 18b809b

Please sign in to comment.