Skip to content

Commit 806d454

Browse files
committed
Refactor to improve Browserify/Webpack bundling
This refactors this package to be more inline with how react-intl is structured. The `"browser"` field has been added to the `package.json` to ignore all the locale data, expect English, when bundling with Browserify or Webpack.
1 parent e5e8ff8 commit 806d454

File tree

6 files changed

+33
-14
lines changed

6 files changed

+33
-14
lines changed

Gruntfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ module.exports = function (grunt) {
5454
options: {
5555
prelude: [
5656
'// GENERATED FILE',
57-
'var DustIntl = require("./helpers");\n\n'
57+
'var DustIntl = require("./dust-intl");\n\n'
5858
].join('\n'),
5959

6060
wrapEntry: function (entry) {

index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/* jshint node:true */
22
'use strict';
33

4-
// Add all locale data to `DustIntl`.
4+
// Add all locale data to `DustIntl`. This module will be ignored when bundling
5+
// for the browser with Browserify/Webpack.
56
require('./lib/locales');
67

7-
exports = module.exports = require('./lib/helpers');
8+
exports = module.exports = require('./lib/dust-intl');

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
},
2424
"main": "index.js",
2525
"jsnext:main": "src/main.js",
26+
"browser": {
27+
"./lib/locales": false,
28+
"./lib/locales.js": false
29+
},
2630
"engines": {
2731
"node": ">=0.10.0",
2832
"npm": ">=1.4.0"

src/dust-intl.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
Copyright (c) 2014, Yahoo! Inc. All rights reserved.
3+
Copyrights licensed under the New BSD License.
4+
See the accompanying LICENSE file for terms.
5+
*/
6+
7+
/* jshint esnext: true */
8+
9+
import IntlMessageFormat from 'intl-messageformat';
10+
import IntlRelativeFormat from 'intl-relativeformat';
11+
12+
import {registerWith} from './helpers.js';
13+
import defaultLocale from './en.js';
14+
15+
export {registerWith};
16+
17+
export function __addLocaleData(data) {
18+
IntlMessageFormat.__addLocaleData(data);
19+
IntlRelativeFormat.__addLocaleData(data);
20+
}
21+
22+
__addLocaleData(defaultLocale);

src/helpers.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import {
1717
getFormatOptions,
1818
getLocales,
1919
tap
20-
} from './utils';
20+
} from './utils.js';
2121

22-
export {registerWith, __addLocaleData};
22+
export {registerWith};
2323

2424
// -----------------------------------------------------------------------------
2525

@@ -62,11 +62,6 @@ function deprecate(name, suggestion) {
6262
};
6363
}
6464

65-
function __addLocaleData(data) {
66-
IntlMessageFormat.__addLocaleData(data);
67-
IntlRelativeFormat.__addLocaleData(data);
68-
}
69-
7065
// -- Helpers ------------------------------------------------------------------
7166

7267
/**

src/main.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ See the accompanying LICENSE file for terms.
66

77
/* jshint esnext: true */
88

9-
import {registerWith, __addLocaleData} from './helpers';
10-
import defaultLocale from './en';
11-
12-
__addLocaleData(defaultLocale);
9+
import {registerWith, __addLocaleData} from './dust-intl.js';
1310

1411
// Re-export as default for
1512
export default {

0 commit comments

Comments
 (0)