@commercetools-frontend/babel-preset-mc-app 22.37.0 → 22.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/create.js +13 -0
- package/package.json +2 -1
- package/production.spec.js +94 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @commercetools-frontend/babel-preset-mc-app
|
|
2
2
|
|
|
3
|
+
## 22.38.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#3672](https://github.com/commercetools/merchant-center-application-kit/pull/3672) [`5c33a40`](https://github.com/commercetools/merchant-center-application-kit/commit/5c33a40910d1f46d3d28080f666150fe1d002757) Thanks [@ragafus](https://github.com/ragafus)! - Add `babel-plugin-formatjs` to avoid bloating bundles with useless data from `formatjs` messages (`description`, `defaultMessage` props). Opt-in flags:
|
|
8
|
+
|
|
9
|
+
- i18nAst: pre-parse defaultMessage into AST for faster runtime perf
|
|
10
|
+
- i18nRemoveDefaultMessage: remove defaultMessage field in generated js after extraction
|
|
11
|
+
|
|
3
12
|
## 22.37.0
|
|
4
13
|
|
|
5
14
|
## 22.36.0
|
package/create.js
CHANGED
|
@@ -22,6 +22,12 @@ const defaultOptions = {
|
|
|
22
22
|
// it explicitely. This will disable `core-js` for `preset-env` and the
|
|
23
23
|
// `plugin-transform-runtime`.
|
|
24
24
|
disableCoreJs: false,
|
|
25
|
+
// If `formatjs` should pre-parse defaultMessage into AST.
|
|
26
|
+
// https://formatjs.github.io/docs/tooling/babel-plugin/#ast
|
|
27
|
+
i18nAst: false,
|
|
28
|
+
// If `formatjs` default messages should be removed from the bundle or not.
|
|
29
|
+
// https://formatjs.github.io/docs/tooling/babel-plugin#removedefaultmessage
|
|
30
|
+
i18nRemoveDefaultMessage: false,
|
|
25
31
|
};
|
|
26
32
|
|
|
27
33
|
/* eslint-disable global-require */
|
|
@@ -189,6 +195,13 @@ module.exports = function createBabePresetConfigForMcApp(api, opts = {}, env) {
|
|
|
189
195
|
require('@emotion/babel-plugin').default,
|
|
190
196
|
// Cherry-pick Lodash modules
|
|
191
197
|
require('babel-plugin-lodash').default,
|
|
198
|
+
[
|
|
199
|
+
require('babel-plugin-formatjs').default,
|
|
200
|
+
{
|
|
201
|
+
ast: options.i18nAst,
|
|
202
|
+
removeDefaultMessage: options.i18nRemoveDefaultMessage,
|
|
203
|
+
},
|
|
204
|
+
],
|
|
192
205
|
].filter(Boolean),
|
|
193
206
|
};
|
|
194
207
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools-frontend/babel-preset-mc-app",
|
|
3
|
-
"version": "22.
|
|
3
|
+
"version": "22.38.0",
|
|
4
4
|
"description": "Babel preset used by a MC application",
|
|
5
5
|
"bugs": "https://github.com/commercetools/merchant-center-application-kit/issues",
|
|
6
6
|
"repository": {
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"@emotion/babel-plugin": "^11.11.0",
|
|
43
43
|
"@emotion/babel-preset-css-prop": "^11.11.0",
|
|
44
44
|
"babel-plugin-dev-expression": "^0.2.3",
|
|
45
|
+
"babel-plugin-formatjs": "^10.5.25",
|
|
45
46
|
"babel-plugin-lodash": "^3.3.4",
|
|
46
47
|
"babel-plugin-macros": "^3.1.0",
|
|
47
48
|
"babel-plugin-preval": "^5.1.0",
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { transformSync } from '@babel/core';
|
|
2
|
+
import getBabePresetConfigForMcAppForProduction from './production';
|
|
3
|
+
|
|
4
|
+
describe('babel-plugin-formatjs', () => {
|
|
5
|
+
const code = `
|
|
6
|
+
import { defineMessages } from 'react-intl';
|
|
7
|
+
|
|
8
|
+
const messages = defineMessages({
|
|
9
|
+
welcome: {
|
|
10
|
+
id: 'app.welcome',
|
|
11
|
+
defaultMessage: 'Welcome, {name}!',
|
|
12
|
+
description: 'Message to greet the user by name',
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
it('should remove description by default', () => {
|
|
18
|
+
const config = getBabePresetConfigForMcAppForProduction(null);
|
|
19
|
+
|
|
20
|
+
const result = transformSync(code, {
|
|
21
|
+
filename: 'dummy-file-name.js',
|
|
22
|
+
presets: config.presets,
|
|
23
|
+
plugins: config.plugins,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
expect(result.code).toMatchInlineSnapshot(`
|
|
27
|
+
""use strict";
|
|
28
|
+
|
|
29
|
+
var _reactIntl = require("react-intl");
|
|
30
|
+
const messages = (0, _reactIntl.defineMessages)({
|
|
31
|
+
welcome: {
|
|
32
|
+
id: "app.welcome",
|
|
33
|
+
defaultMessage: "Welcome, {name}!"
|
|
34
|
+
}
|
|
35
|
+
});"
|
|
36
|
+
`);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should remove defaultMessage when i18nRemoveDefaultMessage is true', () => {
|
|
40
|
+
const config = getBabePresetConfigForMcAppForProduction(null, {
|
|
41
|
+
i18nRemoveDefaultMessage: true,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const result = transformSync(code, {
|
|
45
|
+
filename: 'dummy-file-name.js',
|
|
46
|
+
presets: config.presets,
|
|
47
|
+
plugins: config.plugins,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
expect(result.code).toMatchInlineSnapshot(`
|
|
51
|
+
""use strict";
|
|
52
|
+
|
|
53
|
+
var _reactIntl = require("react-intl");
|
|
54
|
+
const messages = (0, _reactIntl.defineMessages)({
|
|
55
|
+
welcome: {
|
|
56
|
+
id: "app.welcome"
|
|
57
|
+
}
|
|
58
|
+
});"
|
|
59
|
+
`);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('should parse defaultMessage into AST when i18nAst is true', () => {
|
|
63
|
+
const config = getBabePresetConfigForMcAppForProduction(null, {
|
|
64
|
+
i18nAst: true,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const result = transformSync(code, {
|
|
68
|
+
filename: 'dummy-file-name.js',
|
|
69
|
+
presets: config.presets,
|
|
70
|
+
plugins: config.plugins,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
expect(result.code).toMatchInlineSnapshot(`
|
|
74
|
+
""use strict";
|
|
75
|
+
|
|
76
|
+
var _reactIntl = require("react-intl");
|
|
77
|
+
const messages = (0, _reactIntl.defineMessages)({
|
|
78
|
+
welcome: {
|
|
79
|
+
id: "app.welcome",
|
|
80
|
+
defaultMessage: [{
|
|
81
|
+
"type": 0,
|
|
82
|
+
"value": "Welcome, "
|
|
83
|
+
}, {
|
|
84
|
+
"type": 1,
|
|
85
|
+
"value": "name"
|
|
86
|
+
}, {
|
|
87
|
+
"type": 0,
|
|
88
|
+
"value": "!"
|
|
89
|
+
}]
|
|
90
|
+
}
|
|
91
|
+
});"
|
|
92
|
+
`);
|
|
93
|
+
});
|
|
94
|
+
});
|