Skip to content

Commit

Permalink
feat: generate .mjs instead of lib
Browse files Browse the repository at this point in the history
  • Loading branch information
Long Ho committed Aug 6, 2019
1 parent 42cb46e commit 5fd070d
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 48 deletions.
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ dist/**/*.js
examples/**/node_modules/**/*.js
examples/**/build/**/*.js
examples/hello-world/bundle.js
lib/**/*.js
locale-data/**/*.js
src/en.js
src/locale-data/*.js
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ src/en.js
core.js
core.d.ts
.cache
.rpt2_cache
66 changes: 39 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 12 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@
"type": "git",
"url": "git@github.com:yahoo/react-intl.git"
},
"main": "./dist/index.js",
"module": "./lib/index.js",
"main": "./dist/index",
"types": "./dist/index.d.ts",
"type": "module",
"browserify-shim": {
"react": "global:React"
},
"dependencies": {
"@formatjs/intl-relativetimeformat": "^2.5.1",
"@formatjs/intl-relativetimeformat": "^2.5.2",
"@types/hoist-non-react-statics": "^3.3.1",
"@types/invariant": "^2.2.30",
"@types/react": "^16.0.0",
"hoist-non-react-statics": "^3.3.0",
"intl-format-cache": "^4.1.5",
"intl-locales-supported": "^1.4.2",
"intl-messageformat": "^6.0.2",
"intl-messageformat-parser": "^3.0.1",
"intl-format-cache": "^4.1.6",
"intl-locales-supported": "^1.4.3",
"intl-messageformat": "^6.0.3",
"intl-messageformat-parser": "^3.0.2",
"invariant": "^2.1.1",
"react": "^16.3.0",
"shallow-equal": "^1.1.0"
Expand All @@ -68,7 +68,7 @@
"@typescript-eslint/eslint-plugin": "^1.13.0",
"@typescript-eslint/parser": "^1.13.0",
"babel-jest": "^24.8.0",
"babel-plugin-react-intl": "^4.1.5",
"babel-plugin-react-intl": "^4.1.6",
"babel-plugin-transform-member-expression-literals": "^6.9.4",
"babel-plugin-transform-property-literals": "^6.9.4",
"babel-plugin-transform-react-remove-prop-types": "^0.4.18",
Expand Down Expand Up @@ -99,10 +99,11 @@
"react-dom": "^16.8.6",
"rimraf": "^2.4.2",
"rollup": "^1.19.3",
"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-commonjs": "^10.0.2",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-replace": "^2.0.0",
"rollup-plugin-typescript": "^1.0.1",
"rollup-plugin-typescript2": "^0.22.1",
"rollup-plugin-uglify": "^6.0.0",
"serialize-javascript": "^1.5.0",
"standard-version": "^7.0.0",
Expand All @@ -118,14 +119,15 @@
"build:dist:dev": "cross-env NODE_ENV=development rollup -c rollup.config.dist.js",
"build:dist:prod": "cross-env NODE_ENV=production rollup -c rollup.config.dist.js",
"build:dist": "npm run build:dist:dev && npm run build:dist:prod",
"build:lib": "tsc -p src/tsconfig.json && tsc -p src/tsconfig.cjs.json",
"build:lib": "tsc -p src/tsconfig.json && npm run mjs && tsc -p src/tsconfig.cjs.json",
"build": "npm run build:lib && npm run build:dist",
"clean": "rimraf coverage/ dist/ lib/ core.js core.d.ts",
"example": "parcel examples/index.html",
"format:fix": "prettier --write '**/*.{js,md,jsx,ts,tsx}'",
"format": "prettier --check '**/*.{js,md,jsx,ts,tsx}'",
"lint:fix": "eslint . --fix",
"lint": "eslint .",
"mjs": "find ./dist -depth -name \"*.js\" -exec sh -c 'f=\"{}\"; mv -- \"$f\" \"${f%.js}.mjs\"' \\;",
"postchangelog": "npm run toc && npm run format:fix",
"prerelease": "npm run clean && npm run build && npm run test:all",
"release": "standard-version",
Expand Down
22 changes: 16 additions & 6 deletions rollup.config.dist.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import nodeResolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import replace from 'rollup-plugin-replace';
import {uglify} from 'rollup-plugin-uglify';
import typescript from 'rollup-plugin-typescript';
import babel from 'rollup-plugin-babel';

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

Expand All @@ -21,10 +21,20 @@ const plugins = [
},
}),
nodeResolve(),
typescript({
target: 'es5',
module: 'es6',
include: ['*.js+(|x)', '**/*.js+(|x)'],
babel({
configFile: false,
presets: [
[
'@babel/preset-env',
{
targets: {
ie: '11',
esmodules: true,
},
modules: false,
},
],
],
}),
commonjs({
sourcemap: true,
Expand All @@ -37,7 +47,7 @@ const plugins = [

export default [
{
input: p.resolve('lib/index.js'),
input: p.resolve('dist/index.mjs'),
output: {
file: p.resolve(`dist/react-intl.${isProduction ? 'min.js' : 'js'}`),
format: 'umd',
Expand Down
1 change: 0 additions & 1 deletion src/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../dist",
"module": "commonjs",
"target": "es5",
}
Expand Down
2 changes: 1 addition & 1 deletion src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../lib",
"outDir": "../dist",
"baseUrl": ".",
"lib": ["dom", "es2015", "esnext.intl", "es2018.intl", "es2017.intl"]
}
Expand Down
3 changes: 1 addition & 2 deletions test/functional/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import buildTests from './support/build';
import formatTests from './support/format';

const builds = {
ES: p.resolve(require('../../package.json').module),
CJS: p.resolve(require('../../package.json').main),
Main: p.resolve(require('../../package.json').main),
'UMD-dev': p.resolve('dist/react-intl.js'),
'UMD-prod': p.resolve('dist/react-intl.min.js'),
};
Expand Down

0 comments on commit 5fd070d

Please sign in to comment.