Skip to content

Commit 7e05a53

Browse files
author
Setsun
committed
fix(node): add distinct entry points for node.js / browser bundles
1 parent 2142faa commit 7e05a53

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"license": "MIT",
66
"description": "Easily configurable React components for animations / transitions 💃",
77
"repository": "https://github.com/Setsun/react-transition-components",
8-
"module": "src/index.js",
9-
"main": "dist/index.js",
8+
"main": "dist/node/index.js",
9+
"browser": "dist/index.js",
1010
"types": "dist/types/index.d.ts",
1111
"engines": {
1212
"npm": "^6.0.0"
@@ -20,7 +20,9 @@
2020
],
2121
"scripts": {
2222
"start": "cross-env NODE_ENV=development webpack --config webpack.config.js --watch",
23-
"build": "cross-env NODE_ENV=production webpack --config webpack.config.js && tsc",
23+
"build": "cross-env npm run build:browser && npm run build:node && tsc",
24+
"build:browser": "cross-env NODE_ENV=production webpack --config webpack.config.js",
25+
"build:node": "cross-env NODE_ENV=production TARGET_ENV=node webpack --config webpack.config.js",
2426
"test": "jest src/*",
2527
"typecheck": "tsc --noEmit --jsx react src/*",
2628
"typegen": "tsc",

webpack.config.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@ const path = require('path');
33
const src = path.resolve(__dirname, 'src');
44
const dist = path.resolve(__dirname, 'dist');
55

6+
const isNode = process.env.TARGET_ENV === 'node';
7+
const target = isNode ? 'node' : 'web';
8+
const filename = isNode ? 'node/index.js' : 'index.js';
9+
610
module.exports = {
711
mode: 'production',
8-
target: 'web',
12+
target: target,
913
context: src,
1014
entry: 'index.ts',
1115
output: {
1216
path: dist,
13-
filename: 'index.js',
17+
filename: filename,
1418
publicPath: '/',
1519
libraryTarget: 'umd',
1620
},

0 commit comments

Comments
 (0)