Skip to content

Commit 5d81f33

Browse files
update webpack and rollup configs
1 parent aad4c48 commit 5d81f33

File tree

6 files changed

+938
-322
lines changed

6 files changed

+938
-322
lines changed

.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ webpack*
1111
rollup*
1212
.babelrc.js
1313

14+
#development
15+
/build
16+
1417
#demo
1518
/example
1619
index.html

package-lock.json

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

package.json

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,10 @@
1818
"watch": "npm-run-all --parallel watch:*",
1919
"watch:scss": "sass --watch themes/scss:themes style/scss:style --no-source-map",
2020
"watch:js": "cross-env BABEL_OUTPUT=umd INCLUDE_POLYFILLS=true webpack --config webpack.config.js --env=development --watch",
21-
"build": "npm-run-all clean:* --parallel build:lib:* build:scss:* & npm-run-all --parallel build:umd:*",
22-
"build:umd:dev": "cross-env BABEL_OUTPUT=umd INCLUDE_POLYFILLS=true webpack --config webpack.config.js --env=development",
23-
"build:umd:prod": "rollup -c",
24-
"build:umd:prod-pf": "cross-env INCLUDE_POLYFILLS=true rollup -c",
21+
"build": "npm-run-all clean:* --parallel build:lib:* build:scss:* & npm run build:dist",
22+
"build:dist": "rollup -c",
2523
"build:lib:cjs": "cross-env BABEL_OUTPUT=cjs babel src/ --out-dir lib/cjs/ --ignore **/__tests__,**/__mocks__,**/*.test.js,**/*.js.snap",
2624
"build:lib:esm": "babel src/ --out-dir lib/esm/ --ignore **/__tests__,**/__mocks__,**/*.test.js,**/*.js.snap",
27-
"build:lib:esm-pf": "cross-env INCLUDE_POLYFILLS=true babel src/ --out-dir lib/esm-including-polyfills/ --ignore **/__tests__,**/__mocks__,**/*.test.js,**/*.js.snap",
2825
"build:scss:dev": "sass themes/scss:themes style/scss:style --no-source-map",
2926
"build:scss:pro": "sass themes/minified-scss:themes style/minified-scss:style --style compressed --no-source-map",
3027
"clean:lib": "rimraf lib",
@@ -49,8 +46,7 @@
4946
"@babel/preset-env": "^7.11.0",
5047
"@babel/preset-react": "^7.10.4",
5148
"@babel/runtime-corejs3": "^7.13.10",
52-
"@rollup/plugin-commonjs": "^18.0.0",
53-
"@rollup/plugin-node-resolve": "^11.2.1",
49+
"@rollup/plugin-node-resolve": "^13.1.3",
5450
"babel-loader": "^8.1.0",
5551
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
5652
"cross-env": "^7.0.3",

rollup.config.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import {terser} from 'rollup-plugin-terser';
2-
import commonjs from '@rollup/plugin-commonjs';
2+
import pkg from './package.json';
33
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',
4+
const getConfig = (en) => ({
5+
input: pkg.module,
76
output: {
8-
file: requirePolyfills ? 'dist/react-dyn-tabs.including-polyfills.umd.min.js' : 'dist/react-dyn-tabs.umd.min.js',
7+
file: en === 'dev' ? 'dist/react-dyn-tabs.umd.js' : 'dist/react-dyn-tabs.umd.min.js',
98
format: 'umd',
109
name: 'useDynTabs',
1110
globals: {
@@ -15,8 +14,15 @@ export default {
1514
},
1615
sourcemap: true,
1716
},
18-
plugins: [terser(), commonjs(), nodeResolve({preferBuiltins: false})],
17+
plugins: (function () {
18+
const _plugins = [nodeResolve({preferBuiltins: false})];
19+
if (en === 'prod') {
20+
_plugins.push(terser());
21+
}
22+
return _plugins;
23+
})(),
1924
external: function (id) {
2025
return /prop-types$|react$|react-dom$|.test.js$|.js.snap$|.css$/g.test(id);
2126
},
22-
};
27+
});
28+
export default [getConfig('dev'), getConfig('prod')];

webpack.config.js

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
11
const path = require('path');
22
const pkg = require('./package.json');
33
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
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, 'build'),
11+
library: libraryName,
12+
libraryTarget: 'umd',
13+
publicPath: '/build/',
14+
umdNamedDefine: true,
15+
},
16+
devtool: isProduction ? 'source-map' : 'inline-source-map',
17+
mode: env,
18+
module: {
19+
rules: [
20+
{
21+
test: /\.m?js$/,
22+
exclude: /(node_modules|bower_components)/,
23+
use: {
24+
loader: 'babel-loader',
25+
},
1526
},
16-
devtool: isProduction ? 'source-map' : 'inline-source-map',
17-
mode: env,
18-
module: {
19-
rules: [
20-
{
21-
test: /\.m?js$/,
22-
exclude: /(node_modules|bower_components)/,
23-
use: {
24-
loader: 'babel-loader'
25-
}
26-
},
27-
{
28-
test: /\.css$/i,
29-
use: ['style-loader', 'css-loader'],
30-
}
31-
]
27+
{
28+
test: /\.css$/i,
29+
use: ['style-loader', 'css-loader'],
3230
},
33-
resolve: {
34-
alias: {
35-
'assets': path.resolve(__dirname, 'assets')
36-
}
37-
},
38-
externals: {
39-
react: {
40-
commonjs: "react",
41-
commonjs2: "react",
42-
amd: "React",
43-
root: "React"
44-
},
45-
"react-dom": {
46-
commonjs: "react-dom",
47-
commonjs2: "react-dom",
48-
amd: "ReactDOM",
49-
root: "ReactDOM"
50-
}
51-
}
52-
};
53-
};
31+
],
32+
},
33+
resolve: {
34+
alias: {
35+
assets: path.resolve(__dirname, 'assets'),
36+
},
37+
},
38+
externals: {
39+
react: {
40+
commonjs: 'react',
41+
commonjs2: 'react',
42+
amd: 'React',
43+
root: 'React',
44+
},
45+
'react-dom': {
46+
commonjs: 'react-dom',
47+
commonjs2: 'react-dom',
48+
amd: 'ReactDOM',
49+
root: 'ReactDOM',
50+
},
51+
},
52+
};
53+
};

0 commit comments

Comments
 (0)