Skip to content

Commit ab20f77

Browse files
committed
fix(*): module bundler for export
Issue: #2
1 parent 6449968 commit ab20f77

9 files changed

+141
-40
lines changed

lib/ConnectViewport.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import wrapDisplayName from 'recompose/wrapDisplayName';
2+
import { wrapDisplayName } from 'recompose';
33

44
import { IScroll, IDimensions } from './index';
55
import ObserveViewport from './ObserveViewport';

lib/ObserveBoundingClientRect.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
const raf = require('raf');
2+
import raf from 'raf';
33

44
import { shallowEqualRect } from './utils';
55
import { IRect } from './types';

lib/ObserveViewport.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
const raf = require('raf');
2+
import raf from 'raf';
33

44
import {
55
Consumer,

lib/ViewportProvider.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import * as React from 'react';
2-
const throttle = require('lodash.throttle');
3-
const debounce = require('lodash.debounce');
4-
const memoizeOne = require('memoize-one');
5-
const memoize =
6-
typeof memoizeOne === 'function' ? memoizeOne : memoizeOne.default;
7-
const raf = require('raf');
2+
import throttle from 'lodash.throttle';
3+
import debounce from 'lodash.debounce';
4+
import memoize from 'memoize-one';
5+
import raf from 'raf';
86

97
import {
108
shallowEqualScroll,

lib/types.d.ts renamed to lib/modules.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ declare module 'raf' {
33
(tick: Function): NodeJS.Timer;
44
cancel: (id: NodeJS.Timer) => void;
55
};
6-
7-
export default raf;
6+
export = raf;
87
}

package-lock.json

Lines changed: 97 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
"version": "0.3.3",
44
"description": "Utility components for working with the viewport in react",
55
"main": "dist/index.js",
6+
"module": "dist/index.es.js",
7+
"types": "dist/index.d.ts",
68
"scripts": {
79
"start": "rm -rf ./.cache && parcel ./examples/index.html --out-dir='examples-dist'",
810
"precompile": "rm -rf dist",
9-
"compile": "tsc --project ./tsconfig.json",
11+
"compile": "rollup -c",
1012
"test": "jest lib",
1113
"fmt": "prettier --write \"lib/*.{ts,tsx}\" \"examples/*.{ts,tsx}\"",
1214
"prepublish": "npm run compile",
@@ -29,6 +31,8 @@
2931
],
3032
"license": "MIT",
3133
"devDependencies": {
34+
"@types/lodash.debounce": "^4.0.4",
35+
"@types/lodash.throttle": "^4.1.4",
3236
"@types/memoize-one": "^3.1.1",
3337
"@types/node": "^10.9.2",
3438
"@types/react": "^16.4.11",
@@ -40,6 +44,8 @@
4044
"prettier": "^1.14.2",
4145
"react": "^16.4.2",
4246
"react-dom": "^16.4.2",
47+
"rollup": "^0.66.0",
48+
"rollup-plugin-typescript2": "^0.17.0",
4349
"ts-jest": "^23.1.4",
4450
"typescript": "^3.0.1"
4551
},

rollup.config.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import typescript from 'rollup-plugin-typescript2';
2+
import pkg from './package.json';
3+
export default {
4+
input: 'lib/index.ts',
5+
output: [
6+
{
7+
file: pkg.main,
8+
format: 'cjs',
9+
},
10+
{
11+
file: pkg.module,
12+
format: 'es',
13+
},
14+
],
15+
external: [
16+
...Object.keys(pkg.dependencies || {}),
17+
...Object.keys(pkg.peerDependencies || {}),
18+
],
19+
plugins: [
20+
typescript({
21+
typescript: require('typescript'),
22+
}),
23+
],
24+
};

tsconfig.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
{
22
"compilerOptions": {
3-
"outDir": "dist",
4-
"module": "CommonJS",
3+
"declaration": true,
4+
"declarationDir": "./dist",
5+
"module": "es6",
6+
"outDir": "./dist",
57
"target": "es5",
68
"lib": ["es6", "dom"],
79
"sourceMap": true,
810
"jsx": "react",
9-
"moduleResolution": "node",
10-
"rootDir": "lib",
11-
"declaration": true,
1211
"forceConsistentCasingInFileNames": true,
1312
"noImplicitReturns": true,
1413
"noImplicitThis": true,
@@ -17,8 +16,7 @@
1716
"suppressImplicitAnyIndexErrors": true,
1817
"noUnusedLocals": true,
1918
"alwaysStrict": true,
20-
"experimentalDecorators": true
21-
19+
"allowSyntheticDefaultImports": true
2220
},
2321
"include": [
2422
"lib/**/*"

0 commit comments

Comments
 (0)