Skip to content

Commit 0d27dc1

Browse files
authored
Use right version of react-hook-form for ie11 bundle (#68)
* chore(deps): add matched * chore: add mergeRollupConfig util * build: extract umd config * fix: use ie11 version of react-hook-form in ie11 bundle
1 parent 36f7816 commit 0d27dc1

File tree

6 files changed

+106
-47
lines changed

6 files changed

+106
-47
lines changed

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@
2323
"scripts": {
2424
"clean": "rimraf dist",
2525
"prebuild": "npm run clean",
26-
"build": "run-p bundle bundle:ie11 bundle:umd",
27-
"bundle": "tsc",
28-
"bundle:ie11": "tsc --outDir dist/ie11 --downlevelIteration --target es5",
29-
"bundle:umd": "rollup -c",
26+
"build": "tsc && rollup -c",
3027
"lint": "eslint '**/*.{js,ts}'",
3128
"lint:fix": "npm run lint -- --fix",
3229
"lint:types": "tsc --noEmit",
@@ -72,6 +69,7 @@
7269
"husky": "^4.2.5",
7370
"jest": "^26.0.1",
7471
"lint-staged": "^10.2.10",
72+
"matched": "^5.0.0",
7573
"npm-run-all": "^4.1.5",
7674
"prettier": "^2.0.5",
7775
"react": "^16.13.1",

rollup.config.js

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,4 @@
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';
1+
import umd from './rollup/umd';
2+
import cjsie11 from './rollup/cjs.ie11';
53

6-
const dir = './dist/umd';
7-
8-
export default {
9-
input: './src/index.ts',
10-
output: {
11-
dir,
12-
name: 'ReactHookFormResolvers',
13-
format: 'umd',
14-
sourcemap: true,
15-
globals: {
16-
'react-hook-form': 'ReactHookForm',
17-
},
18-
exports: 'named',
19-
},
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-
};
4+
export default [umd, cjsie11];

rollup/cjs.ie11.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import glob from 'matched';
2+
import commonjs from '@rollup/plugin-commonjs';
3+
import typescript from 'rollup-plugin-typescript2';
4+
import mergeConfig from './merge-config';
5+
6+
const dir = './dist/ie11';
7+
8+
const config = {
9+
input: glob.sync(['src/**/*.ts', '!src/index.ts', '!src/**/*.test.ts']),
10+
preserveModules: true,
11+
output: {
12+
dir,
13+
format: 'cjs',
14+
paths: {
15+
'react-hook-form': 'react-hook-form/dist/index.ie11',
16+
},
17+
},
18+
plugins: [
19+
commonjs(),
20+
typescript({
21+
clean: true,
22+
tsconfigOverride: {
23+
compilerOptions: {
24+
declaration: false,
25+
module: 'ESNext',
26+
downlevelIteration: true,
27+
target: 'es5',
28+
},
29+
},
30+
}),
31+
],
32+
};
33+
34+
export default mergeConfig(config);

rollup/merge-config.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { terser } from 'rollup-plugin-terser';
2+
import resolve from '@rollup/plugin-node-resolve';
3+
4+
/**
5+
* Merge rollup config with base config
6+
* @param {*} config
7+
*/
8+
export default function mergeRollupConfig(config) {
9+
return {
10+
...config,
11+
external: ['react-hook-form'],
12+
output: {
13+
sourcemap: true,
14+
exports: 'named',
15+
...config.output,
16+
},
17+
plugins: [
18+
resolve({
19+
customResolveOptions: {
20+
moduleDirectory: config.output.dir,
21+
},
22+
}),
23+
terser({
24+
output: { comments: false },
25+
compress: {
26+
drop_console: true,
27+
},
28+
}),
29+
...config.plugins,
30+
],
31+
};
32+
}

rollup/umd.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import typescript from 'rollup-plugin-typescript2';
2+
import mergeConfig from './merge-config';
3+
4+
const dir = './dist/umd';
5+
6+
const config = {
7+
input: './src/index.ts',
8+
output: {
9+
dir,
10+
name: 'ReactHookFormResolvers',
11+
format: 'umd',
12+
globals: {
13+
'react-hook-form': 'ReactHookForm',
14+
},
15+
},
16+
plugins: [
17+
typescript({
18+
clean: true,
19+
tsconfigOverride: {
20+
compilerOptions: { declaration: false, module: 'ESNext' },
21+
},
22+
}),
23+
],
24+
};
25+
26+
export default mergeConfig(config);

yarn.lock

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3184,6 +3184,14 @@ map-visit@^1.0.0:
31843184
dependencies:
31853185
object-visit "^1.0.0"
31863186

3187+
matched@^5.0.0:
3188+
version "5.0.0"
3189+
resolved "https://registry.yarnpkg.com/matched/-/matched-5.0.0.tgz#4b10735a89f87b6f9bf457136472631e19df05d7"
3190+
integrity sha512-O0LCuxYYBNBjP2dmAg0i6PME0Mb0dvjulpMC0tTIeMRh6kXYsugOT5GOWpFkSzqjQjgOUs/eiyvpVhXdN2La4g==
3191+
dependencies:
3192+
glob "^7.1.6"
3193+
picomatch "^2.2.1"
3194+
31873195
memorystream@^0.3.1:
31883196
version "0.3.1"
31893197
resolved "https://registry.yarnpkg.com/memorystream/-/memorystream-0.3.1.tgz#86d7090b30ce455d63fbae12dda51a47ddcaf9b2"
@@ -3604,7 +3612,7 @@ performance-now@^2.1.0:
36043612
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
36053613
integrity sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=
36063614

3607-
picomatch@^2.0.4, picomatch@^2.0.5, picomatch@^2.2.2:
3615+
picomatch@^2.0.4, picomatch@^2.0.5, picomatch@^2.2.1, picomatch@^2.2.2:
36083616
version "2.2.2"
36093617
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.2.2.tgz#21f333e9b6b8eaff02468f5146ea406d345f4dad"
36103618
integrity sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg==

0 commit comments

Comments
 (0)