Skip to content

Commit fa20f9e

Browse files
authored
Fix modules resolution (#60)
* chore(deps): add chalk * chore: update bundles paths * feat: write declaration files (/dist/types) * chore: disable declaration files * feat: generate bundles with preserve modules * refactor: remove useless code * refactor: output dir generation * fix: types module resolution (superstruct) * chore: add & use cpy * chore: new bundle generation * refactor: remove useless code * chore: yarn remove useless code * chore: update bundle format paths * chore: generate declaration files for esm only * refactor: remove chalk * refactor: remove useless code * chore: improve rollup config * refactor: remove useless files * chore(deps): remove useless deps * build: new logic (cjs,ie11,umd) + nested imports
1 parent ce73c6e commit fa20f9e

16 files changed

+287
-262
lines changed

joi.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './dist/joi';

joi.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./dist/joi');

package.json

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,29 @@
22
"name": "@hookform/resolvers",
33
"version": "0.2.0-beta.1",
44
"description": "React Hook Form validation resolvers: Yup, Joi, Superstruct and etc.",
5-
"main": "dist/index.js",
6-
"module": "dist/index.esm.js",
7-
"umd:main": "dist/index.umd.production.min.js",
8-
"unpkg": "dist/index.umd.production.min.js",
9-
"jsdelivr": "dist/index.umd.production.min.js",
10-
"jsnext:main": "dist/index.esm.js",
11-
"source": "src/index.ts",
12-
"types": "dist/index.d.ts",
5+
"umd:main": "umd/index.js",
6+
"unpkg": "umd/index.js",
7+
"jsdelivr": "umd/index.js",
138
"sideEffects": false,
149
"files": [
15-
"dist"
10+
"dist",
11+
"yup.js",
12+
"yup.d.ts",
13+
"joi.js",
14+
"joi.d.ts",
15+
"superstruct.js",
16+
"superstruct.d.ts"
1617
],
1718
"publishConfig": {
1819
"access": "public"
1920
},
2021
"scripts": {
2122
"clean": "rimraf dist",
2223
"prebuild": "npm run clean",
23-
"build": "node rollup/writeCjsEntryFile.js && rollup -c",
24+
"build": "run-p bundle bundle:ie11 bundle:umd",
25+
"bundle": "tsc",
26+
"bundle:ie11": "tsc --outDir dist/ie11 --downlevelIteration --target es5",
27+
"bundle:umd": "rollup -c",
2428
"lint": "eslint '**/*.{js,ts}'",
2529
"lint:fix": "npm run lint -- --fix",
2630
"lint:types": "tsc --noEmit",
@@ -53,9 +57,7 @@
5357
"devDependencies": {
5458
"@hapi/joi": "^17.1.1",
5559
"@rollup/plugin-commonjs": "^13.0.0",
56-
"@rollup/plugin-json": "^4.1.0",
5760
"@rollup/plugin-node-resolve": "^8.0.1",
58-
"@rollup/plugin-replace": "^2.3.3",
5961
"@types/hapi__joi": "^17.1.0",
6062
"@types/jest": "^26.0.0",
6163
"@types/yup": "^0.29.3",
@@ -67,13 +69,12 @@
6769
"husky": "^4.2.5",
6870
"jest": "^26.0.1",
6971
"lint-staged": "^10.2.10",
72+
"npm-run-all": "^4.1.5",
7073
"prettier": "^2.0.5",
7174
"react": "^16.13.1",
7275
"react-hook-form": "^6.7.0",
7376
"rimraf": "^3.0.2",
7477
"rollup": "^2.16.1",
75-
"rollup-plugin-peer-deps-external": "^2.2.2",
76-
"rollup-plugin-sourcemaps": "^0.6.2",
7778
"rollup-plugin-terser": "^6.1.0",
7879
"rollup-plugin-typescript2": "^0.27.1",
7980
"superstruct": "^0.8.3",

rollup.config.js

Lines changed: 40 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,43 @@
1-
import { createRollupConfig } from './rollup/createRollupConfig';
2-
import pkg from './package.json';
1+
import typescript from 'rollup-plugin-typescript2';
2+
import { terser } from 'rollup-plugin-terser';
3+
import resolve from '@rollup/plugin-node-resolve';
4+
import commonjs from '@rollup/plugin-commonjs';
35

4-
const name = 'index';
5-
const umdName = 'ReactHookFormResolvers';
6-
const options = [
7-
{
8-
name,
9-
umdName,
10-
format: 'cjs',
11-
env: 'development',
12-
input: pkg.source,
13-
},
14-
{
15-
name,
16-
umdName,
17-
format: 'cjs',
18-
env: 'production',
19-
input: pkg.source,
20-
},
21-
{
22-
name,
23-
umdName,
24-
format: 'esm',
25-
input: pkg.source,
26-
},
27-
{
28-
name,
29-
umdName,
30-
format: 'umd',
31-
env: 'development',
32-
input: pkg.source,
33-
},
34-
{
35-
name,
36-
umdName,
6+
const dir = './dist/umd';
7+
8+
export default {
9+
input: './src/index.ts',
10+
output: {
11+
dir,
12+
name: 'ReactHookFormResolvers',
3713
format: 'umd',
38-
env: 'production',
39-
input: pkg.source,
14+
sourcemap: true,
15+
globals: {
16+
'react-hook-form': 'ReactHookForm',
17+
},
18+
exports: 'named',
4019
},
41-
{
42-
name,
43-
umdName,
44-
format: 'esm',
45-
formatName: 'ie11',
46-
input: pkg.source,
47-
tsconfig: './tsconfig.ie11.json',
48-
},
49-
];
50-
51-
export default options.map((option) => createRollupConfig(option));
20+
external: ['react-hook-form'],
21+
plugins: [
22+
typescript({
23+
clean: true,
24+
tsconfigOverride: {
25+
compilerOptions: { declaration: false, module: 'ESNext' },
26+
},
27+
}),
28+
resolve({
29+
customResolveOptions: {
30+
moduleDirectory: dir,
31+
},
32+
}),
33+
commonjs({
34+
include: /\/node_modules\//,
35+
}),
36+
terser({
37+
output: { comments: false },
38+
compress: {
39+
drop_console: true,
40+
},
41+
}),
42+
],
43+
};

rollup/createRollupConfig.js

Lines changed: 0 additions & 79 deletions
This file was deleted.

rollup/pascalcase.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

rollup/safePackageName.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

rollup/writeCjsEntryFile.js

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/index.ie11.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

superstruct.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./dist/superstruct');

0 commit comments

Comments
 (0)