Skip to content

Commit 737274f

Browse files
add babel config, rollup
config and webpack config + update package.json
1 parent 13a2283 commit 737274f

File tree

4 files changed

+176
-32
lines changed

4 files changed

+176
-32
lines changed

.babelrc.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
const output = process.env.BABEL_OUTPUT;
4+
const requirePolyfills = process.env.INCLUDE_POLYFILLS;
5+
const modules = output == null ? false : output;
6+
const options = {
7+
presets: [['@babel/env', { loose: true, modules }], '@babel/react'],
8+
plugins: [
9+
'@babel/plugin-transform-react-jsx'
10+
],
11+
env: {
12+
test: { // extra configuration for process.env.NODE_ENV === 'test'
13+
presets: ['@babel/env'] // overwrite env-config from above with transpiled module syntax
14+
}
15+
}
16+
};
17+
if (requirePolyfills) {
18+
options.plugins.push([
19+
'@babel/plugin-transform-runtime',
20+
{ corejs: 3 }
21+
]);
22+
}
23+
module.exports = options;

package.json

Lines changed: 75 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,81 @@
11
{
2-
"name": "react-dynamic-tabs",
3-
"version": "0.1.0",
4-
"private": true,
5-
"dependencies": {
6-
"@testing-library/jest-dom": "^4.2.4",
7-
"@testing-library/react": "^9.3.2",
8-
"@testing-library/user-event": "^7.1.2",
9-
"react": "^16.13.0",
10-
"react-dom": "^16.13.0",
11-
"react-scripts": "3.4.0"
12-
},
2+
"name": "react-dyn-tabs",
3+
"version": "1.0.0",
4+
"private": false,
5+
"author": "dev-javascript",
6+
"description": "dynamic tabs, full control and api based Tab for ReactJs",
7+
"main": "lib/cjs/index.js",
8+
"module": "lib/esm/index.js",
139
"scripts": {
14-
"start": "react-scripts start",
15-
"build": "react-scripts build",
16-
"test": "react-scripts test",
17-
"test:debug": "react-scripts --inspect-brk test --runInBand --no-cache",
18-
"eject": "react-scripts eject"
19-
},
20-
"eslintConfig": {
21-
"extends": "react-app"
10+
"prebuild": "npm-run-all clean:* --parallel",
11+
"build": "npm run build:lib & npm-run-all --parallel build:umd:prod* & npm run build:umd:dev",
12+
"build:umd:dev": "cross-env BABEL_OUTPUT=umd INCLUDE_POLYFILLS=true webpack --config webpack.config.js --env=development",
13+
"build:umd:prod": "rollup -c",
14+
"build:umd:prod-pf": "cross-env INCLUDE_POLYFILLS=true rollup -c",
15+
"build:lib": "npm-run-all --parallel build:lib:*",
16+
"build:lib:cjs": "cross-env BABEL_OUTPUT=cjs babel src/ --out-dir lib/cjs/ --ignore **/__tests__,**/__mocks__,**/*.test.js,**/*.js.snap",
17+
"build:lib:esm": "babel src/ --out-dir lib/esm/ --ignore **/__tests__,**/__mocks__,**/*.test.js,**/*.js.snap",
18+
"build:lib:esm-pf": "cross-env INCLUDE_POLYFILLS=true babel src/ --out-dir lib/esm-including-polyfills/ --ignore **/__tests__,**/__mocks__,**/*.test.js,**/*.js.snap",
19+
"clean:lib": "rimraf lib",
20+
"clean:dist": "rimraf dist",
21+
"prepublish": "npm run build",
22+
"test": "echo \"Error: no test specified\" && exit 1"
2223
},
23-
"browserslist": {
24-
"production": [
25-
">0.2%",
26-
"not dead",
27-
"not op_mini all"
28-
],
29-
"development": [
30-
"last 1 chrome version",
31-
"last 1 firefox version",
32-
"last 1 safari version"
33-
]
24+
"peerDependencies": {
25+
"@babel/runtime-corejs3": "^7.13.10",
26+
"react": "^17.0.1",
27+
"react-dom": "^17.0.1"
3428
},
3529
"devDependencies": {
36-
"react-test-renderer": "^16.13.1"
37-
}
30+
"@babel/cli": "^7.13.14",
31+
"@babel/core": "^7.11.4",
32+
"@babel/plugin-transform-react-jsx": "^7.10.4",
33+
"@babel/plugin-transform-react-jsx-self": "^7.10.4",
34+
"@babel/plugin-transform-runtime": "^7.13.10",
35+
"@babel/preset-env": "^7.11.0",
36+
"@babel/preset-react": "^7.10.4",
37+
"@babel/runtime-corejs3": "^7.13.10",
38+
"@rollup/plugin-commonjs": "^18.0.0",
39+
"@rollup/plugin-node-resolve": "^11.2.1",
40+
"babel-loader": "^8.1.0",
41+
"cross-env": "^7.0.3",
42+
"css-loader": "^4.3.0",
43+
"npm-run-all": "^4.1.5",
44+
"react": "^17.0.1",
45+
"react-dom": "^17.0.1",
46+
"reactstrap": "^8.5.1",
47+
"rollup": "^2.41.0",
48+
"rollup-plugin-terser": "7.0.2",
49+
"style-loader": "^1.2.1",
50+
"webpack": "^4.44.1",
51+
"webpack-cli": "^3.3.12"
52+
},
53+
"files": [
54+
"dist",
55+
"docs",
56+
"flow-typed",
57+
"lib",
58+
"src",
59+
"style",
60+
"theme",
61+
"themes"
62+
],
63+
"keywords": [
64+
"react",
65+
"dynamic",
66+
"tab",
67+
"dynamic-tabs",
68+
"multi-tabs",
69+
"react-dynamic-tabs",
70+
"react-dyn-tabs",
71+
"react-component",
72+
"react-tab",
73+
"api-based",
74+
"full-control"
75+
],
76+
"license": "MIT",
77+
"directories": {
78+
"lib": "lib"
79+
},
80+
"dependencies": {}
3881
}

rollup.config.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { terser } from 'rollup-plugin-terser';
2+
import commonjs from '@rollup/plugin-commonjs';
3+
import nodeResolve from '@rollup/plugin-node-resolve';
4+
const requirePolyfills = process.env.INCLUDE_POLYFILLS;
5+
export default {
6+
input: requirePolyfills ? 'lib/esm-including-polyfills/index.js' : 'lib/esm/index.js',
7+
output: {
8+
file: requirePolyfills ? 'dist/react-dyn-tabs.including-polyfills.umd.min.js' : 'dist/react-dyn-tabs.umd.min.js',
9+
format: 'umd',
10+
name: 'useDynTabs',
11+
globals: {
12+
react: 'React',
13+
},
14+
sourcemap: true,
15+
},
16+
plugins: [
17+
terser(),
18+
commonjs(),
19+
nodeResolve({ preferBuiltins: false }), // or `true`
20+
],
21+
external: function (id) {
22+
return (/react$|react-dom$|.test.js$|.js.snap$|.css$/g).test(id);
23+
}
24+
};

webpack.config.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
const path = require('path');
2+
const pkg = require('./package.json');
3+
const libraryName = pkg.name;
4+
module.exports = env => {
5+
const isProduction = env === 'production';
6+
return {
7+
entry: './src/index.js',
8+
output: {
9+
filename: isProduction ? 'react-dyn-tabs.umd.min.js' : 'react-dyn-tabs.umd.js',
10+
path: path.resolve(__dirname, 'dist'),
11+
library: libraryName,
12+
libraryTarget: 'umd',
13+
publicPath: '/dist/',
14+
umdNamedDefine: true
15+
},
16+
devtool: isProduction ? 'source-map' : 'inline-source-map',
17+
mode: env,
18+
watch: !isProduction,
19+
module: {
20+
rules: [
21+
{
22+
test: /\.m?js$/,
23+
exclude: /(node_modules|bower_components)/,
24+
use: {
25+
loader: 'babel-loader'
26+
}
27+
},
28+
{
29+
test: /\.css$/i,
30+
use: ['style-loader', 'css-loader'],
31+
}
32+
]
33+
},
34+
resolve: {
35+
alias: {
36+
'assets': path.resolve(__dirname, 'assets')
37+
}
38+
},
39+
externals: {
40+
react: {
41+
commonjs: "react",
42+
commonjs2: "react",
43+
amd: "React",
44+
root: "React"
45+
},
46+
"react-dom": {
47+
commonjs: "react-dom",
48+
commonjs2: "react-dom",
49+
amd: "ReactDOM",
50+
root: "ReactDOM"
51+
}
52+
}
53+
};
54+
};

0 commit comments

Comments
 (0)