Skip to content

Commit 5fd070d

Browse files
author
Long Ho
committed
feat: generate .mjs instead of lib
1 parent 42cb46e commit 5fd070d

File tree

8 files changed

+70
-48
lines changed

8 files changed

+70
-48
lines changed

.eslintignore

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ dist/**/*.js
33
examples/**/node_modules/**/*.js
44
examples/**/build/**/*.js
55
examples/hello-world/bundle.js
6-
lib/**/*.js
76
locale-data/**/*.js
87
src/en.js
98
src/locale-data/*.js

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ src/en.js
1414
core.js
1515
core.d.ts
1616
.cache
17+
.rpt2_cache

package-lock.json

+39-27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+12-10
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,22 @@
3030
"type": "git",
3131
"url": "git@github.com:yahoo/react-intl.git"
3232
},
33-
"main": "./dist/index.js",
34-
"module": "./lib/index.js",
33+
"main": "./dist/index",
3534
"types": "./dist/index.d.ts",
35+
"type": "module",
3636
"browserify-shim": {
3737
"react": "global:React"
3838
},
3939
"dependencies": {
40-
"@formatjs/intl-relativetimeformat": "^2.5.1",
40+
"@formatjs/intl-relativetimeformat": "^2.5.2",
4141
"@types/hoist-non-react-statics": "^3.3.1",
4242
"@types/invariant": "^2.2.30",
4343
"@types/react": "^16.0.0",
4444
"hoist-non-react-statics": "^3.3.0",
45-
"intl-format-cache": "^4.1.5",
46-
"intl-locales-supported": "^1.4.2",
47-
"intl-messageformat": "^6.0.2",
48-
"intl-messageformat-parser": "^3.0.1",
45+
"intl-format-cache": "^4.1.6",
46+
"intl-locales-supported": "^1.4.3",
47+
"intl-messageformat": "^6.0.3",
48+
"intl-messageformat-parser": "^3.0.2",
4949
"invariant": "^2.1.1",
5050
"react": "^16.3.0",
5151
"shallow-equal": "^1.1.0"
@@ -68,7 +68,7 @@
6868
"@typescript-eslint/eslint-plugin": "^1.13.0",
6969
"@typescript-eslint/parser": "^1.13.0",
7070
"babel-jest": "^24.8.0",
71-
"babel-plugin-react-intl": "^4.1.5",
71+
"babel-plugin-react-intl": "^4.1.6",
7272
"babel-plugin-transform-member-expression-literals": "^6.9.4",
7373
"babel-plugin-transform-property-literals": "^6.9.4",
7474
"babel-plugin-transform-react-remove-prop-types": "^0.4.18",
@@ -99,10 +99,11 @@
9999
"react-dom": "^16.8.6",
100100
"rimraf": "^2.4.2",
101101
"rollup": "^1.19.3",
102+
"rollup-plugin-babel": "^4.3.3",
102103
"rollup-plugin-commonjs": "^10.0.2",
103104
"rollup-plugin-node-resolve": "^5.2.0",
104105
"rollup-plugin-replace": "^2.0.0",
105-
"rollup-plugin-typescript": "^1.0.1",
106+
"rollup-plugin-typescript2": "^0.22.1",
106107
"rollup-plugin-uglify": "^6.0.0",
107108
"serialize-javascript": "^1.5.0",
108109
"standard-version": "^7.0.0",
@@ -118,14 +119,15 @@
118119
"build:dist:dev": "cross-env NODE_ENV=development rollup -c rollup.config.dist.js",
119120
"build:dist:prod": "cross-env NODE_ENV=production rollup -c rollup.config.dist.js",
120121
"build:dist": "npm run build:dist:dev && npm run build:dist:prod",
121-
"build:lib": "tsc -p src/tsconfig.json && tsc -p src/tsconfig.cjs.json",
122+
"build:lib": "tsc -p src/tsconfig.json && npm run mjs && tsc -p src/tsconfig.cjs.json",
122123
"build": "npm run build:lib && npm run build:dist",
123124
"clean": "rimraf coverage/ dist/ lib/ core.js core.d.ts",
124125
"example": "parcel examples/index.html",
125126
"format:fix": "prettier --write '**/*.{js,md,jsx,ts,tsx}'",
126127
"format": "prettier --check '**/*.{js,md,jsx,ts,tsx}'",
127128
"lint:fix": "eslint . --fix",
128129
"lint": "eslint .",
130+
"mjs": "find ./dist -depth -name \"*.js\" -exec sh -c 'f=\"{}\"; mv -- \"$f\" \"${f%.js}.mjs\"' \\;",
129131
"postchangelog": "npm run toc && npm run format:fix",
130132
"prerelease": "npm run clean && npm run build && npm run test:all",
131133
"release": "standard-version",

rollup.config.dist.js

+16-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import nodeResolve from 'rollup-plugin-node-resolve';
33
import commonjs from 'rollup-plugin-commonjs';
44
import replace from 'rollup-plugin-replace';
55
import {uglify} from 'rollup-plugin-uglify';
6-
import typescript from 'rollup-plugin-typescript';
6+
import babel from 'rollup-plugin-babel';
77

88
const isProduction = process.env.NODE_ENV === 'production';
99

@@ -21,10 +21,20 @@ const plugins = [
2121
},
2222
}),
2323
nodeResolve(),
24-
typescript({
25-
target: 'es5',
26-
module: 'es6',
27-
include: ['*.js+(|x)', '**/*.js+(|x)'],
24+
babel({
25+
configFile: false,
26+
presets: [
27+
[
28+
'@babel/preset-env',
29+
{
30+
targets: {
31+
ie: '11',
32+
esmodules: true,
33+
},
34+
modules: false,
35+
},
36+
],
37+
],
2838
}),
2939
commonjs({
3040
sourcemap: true,
@@ -37,7 +47,7 @@ const plugins = [
3747

3848
export default [
3949
{
40-
input: p.resolve('lib/index.js'),
50+
input: p.resolve('dist/index.mjs'),
4151
output: {
4252
file: p.resolve(`dist/react-intl.${isProduction ? 'min.js' : 'js'}`),
4353
format: 'umd',

src/tsconfig.cjs.json

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"extends": "./tsconfig.json",
33
"compilerOptions": {
4-
"outDir": "../dist",
54
"module": "commonjs",
65
"target": "es5",
76
}

src/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"extends": "../tsconfig.json",
33
"compilerOptions": {
4-
"outDir": "../lib",
4+
"outDir": "../dist",
55
"baseUrl": ".",
66
"lib": ["dom", "es2015", "esnext.intl", "es2018.intl", "es2017.intl"]
77
}

test/functional/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import buildTests from './support/build';
33
import formatTests from './support/format';
44

55
const builds = {
6-
ES: p.resolve(require('../../package.json').module),
7-
CJS: p.resolve(require('../../package.json').main),
6+
Main: p.resolve(require('../../package.json').main),
87
'UMD-dev': p.resolve('dist/react-intl.js'),
98
'UMD-prod': p.resolve('dist/react-intl.min.js'),
109
};

0 commit comments

Comments
 (0)