Skip to content

Commit 2f4d26e

Browse files
authored
Update to webpack4 and simplify build tooling (react-bootstrap#3100)
* Update to webpack4 and simplify build tooling * just use two babelrcs * pin node travis
1 parent f5a00ce commit 2f4d26e

18 files changed

+1513
-2015
lines changed

.babelrc.js

+44-26
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,48 @@
1-
const commonjs = process.env.BABEL_ENV !== 'esm';
1+
module.exports = api => {
2+
let dev = false;
3+
let modules = true;
24

3-
module.exports = {
4-
presets: [
5-
[
6-
'@babel/preset-env',
7-
{
8-
loose: true,
9-
shippedProposals: true,
10-
modules: commonjs ? 'commonjs' : false,
11-
targets: {
12-
browsers: ['last 4 versions', 'not ie <= 8']
5+
switch (api.env()) {
6+
case 'test':
7+
dev = true;
8+
modules = false;
9+
break;
10+
case 'dist-dev':
11+
dev = true;
12+
modules = false;
13+
break;
14+
case 'dist-prod':
15+
case 'esm':
16+
modules = false;
17+
break;
18+
case 'build':
19+
default:
20+
break;
21+
}
22+
23+
return {
24+
presets: [
25+
[
26+
'@babel/preset-env',
27+
{
28+
loose: true,
29+
shippedProposals: true,
30+
modules: modules ? 'commonjs' : false,
31+
targets: {
32+
browsers: ['last 4 versions', 'not ie <= 8']
33+
}
1334
}
14-
}
35+
],
36+
['@babel/preset-react', { development: dev }]
1537
],
16-
[
17-
'@babel/preset-react',
18-
{ development: process.env.NODE_ENV !== 'production' }
19-
]
20-
],
21-
plugins: [
22-
['@babel/plugin-proposal-class-properties', { loose: true }],
23-
'@babel/plugin-proposal-export-default-from',
24-
'@babel/plugin-proposal-export-namespace-from',
25-
['@babel/plugin-transform-runtime', { useESModules: !commonjs }],
26-
'babel-plugin-dev-expression',
27-
commonjs && 'babel-plugin-add-module-exports',
28-
process.env.NODE_ENV === 'test' && 'babel-plugin-istanbul'
29-
].filter(Boolean)
38+
plugins: [
39+
['@babel/plugin-proposal-class-properties', { loose: true }],
40+
'@babel/plugin-proposal-export-default-from',
41+
'@babel/plugin-proposal-export-namespace-from',
42+
['@babel/plugin-transform-runtime', { useESModules: !modules }],
43+
'babel-plugin-dev-expression',
44+
modules && 'babel-plugin-add-module-exports',
45+
api.env() === 'test' && 'babel-plugin-istanbul'
46+
].filter(Boolean)
47+
};
3048
};

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ sudo: false
22

33
language: node_js
44
node_js:
5-
- stable
5+
- '9'
66

77
env:
88
- BROWSER=ChromeCi

karma.conf.js

+16-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
const { plugins, rules } = require('webpack-atoms');
2-
const runBabel = require('./tools/run-babel');
3-
4-
const babelOptions = {
5-
...runBabel.getConfig({ modules: false, test: true }),
6-
cacheDirectory: true
7-
};
1+
const { DefinePlugin } = require('webpack');
82

93
module.exports = config => {
104
const { env } = process;
@@ -19,11 +13,24 @@ module.exports = config => {
1913
},
2014

2115
webpack: {
16+
mode: 'development',
2217
module: {
23-
rules: [rules.js(babelOptions)]
18+
rules: [
19+
{
20+
test: /\.js$/,
21+
exclude: /node_modules/,
22+
use: {
23+
loader: 'babel-loader',
24+
options: {
25+
cacheDirectory: true,
26+
envName: 'test'
27+
}
28+
}
29+
}
30+
]
2431
},
2532
plugins: [
26-
plugins.define({
33+
new DefinePlugin({
2734
'process.env.NODE_ENV': JSON.stringify('test')
2835
})
2936
],

package.json

+32-17
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,31 @@
2424
"tdd": "karma start",
2525
"test": "npm run lint && npm run test-browser && npm run test-node",
2626
"test-browser": "cross-env NODE_ENV=test karma start --single-run",
27-
"test-node": "mocha --compilers js:@babel/register test/server/*Spec.js",
27+
"test-node": "cross-env NODE_ENV=test-server mocha --compilers js:@babel/register test/server/*Spec.js",
2828
"storybook": "start-storybook -p 6006",
2929
"build-storybook": "build-storybook"
3030
},
3131
"lint-staged": {
32-
"*.js": ["npm run ci-lint -- --fix", "git add"]
32+
"*.js": [
33+
"npm run ci-lint -- --fix",
34+
"git add"
35+
]
3336
},
3437
"prettier": {
3538
"singleQuote": true
3639
},
37-
"files": ["CHANGELOG.md", "lib", "dist", "es"],
38-
"keywords": ["react", "ecosystem-react", "react-component", "bootstrap"],
40+
"files": [
41+
"CHANGELOG.md",
42+
"lib",
43+
"dist",
44+
"es"
45+
],
46+
"keywords": [
47+
"react",
48+
"ecosystem-react",
49+
"react-component",
50+
"bootstrap"
51+
],
3952
"author": "Stephen J. Collings <[email protected]>",
4053
"license": "MIT",
4154
"peerDependencies": {
@@ -59,51 +72,53 @@
5972
"babel-plugin-dev-expression": "^0.2.1",
6073
"babel-plugin-istanbul": "^4.1.5",
6174
"chai": "^3.5.0",
75+
"chalk": "^2.3.2",
6276
"codecov": "^2.2.0",
63-
"colors": "^1.1.2",
77+
"colors": "^1.2.1",
6478
"create-react-class": "^15.6.3",
6579
"cross-env": "^2.0.0",
6680
"enzyme": "^3.1.0",
67-
"enzyme-adapter-react-15": "^1.0.1",
68-
"eslint": "^4.18.2",
81+
"eslint": "^4.19.1",
6982
"eslint-config-airbnb": "^15.1.0",
7083
"eslint-config-prettier": "^2.9.0",
71-
"eslint-plugin-import": "^2.9.0",
84+
"eslint-plugin-import": "^2.10.0",
7285
"eslint-plugin-jsx-a11y": "^5.1.1",
7386
"eslint-plugin-mocha": "^4.12.1",
7487
"eslint-plugin-prettier": "^2.6.0",
7588
"eslint-plugin-react": "^7.7.0",
89+
"execa": "^0.10.0",
7690
"fs-extra": "^5.0.0",
7791
"husky": "^0.14.3",
78-
"karma": "^1.1.1",
79-
"karma-chrome-launcher": "^1.0.1",
92+
"karma": "^2.0.0",
93+
"karma-chrome-launcher": "^2.2.0",
8094
"karma-cli": "^1.0.1",
8195
"karma-coverage": "^1.1.0",
8296
"karma-firefox-launcher": "^1.0.0",
8397
"karma-mocha": "^1.1.1",
8498
"karma-mocha-reporter": "^2.0.4",
8599
"karma-sinon-chai": "^1.2.2",
86100
"karma-sourcemap-loader": "^0.3.7",
87-
"karma-webpack": "^2.0.13",
101+
"karma-webpack": "^3.0.0",
88102
"lint-staged": "^6.0.0",
89103
"lodash": "^4.17.5",
90-
"mocha": "^2.5.3",
104+
"mocha": "^5.0.5",
91105
"prettier": "^1.11.1",
92106
"react": "^15.5.4",
93107
"react-dom": "^15.5.4",
94108
"react-test-renderer": "^15.6.2",
95109
"release-script": "^1.0.2",
96110
"sinon": "^2.3.2",
97111
"sinon-chai": "^2.8.0",
98-
"webpack": "^3.6.0",
99-
"webpack-atoms": "^5.1.1"
112+
"webpack": "^4.4.1"
100113
},
101114
"dependencies": {
102-
"@babel/runtime": "^7.0.0-beta.40",
115+
"@babel/runtime": "^7.0.0-beta.42",
116+
"babel-loader": "^8.0.0-beta.2",
103117
"classnames": "^2.2.5",
104118
"dom-helpers": "^3.2.0",
105-
"invariant": "^2.2.3",
106-
"keycode": "^2.1.2",
119+
"enzyme-adapter-react-15": "^1.0.1",
120+
"invariant": "^2.2.4",
121+
"keycode": "^2.2.0",
107122
"prop-types": "^15.6.1",
108123
"prop-types-extra": "^1.0.1",
109124
"react-overlays": "^0.8.0",

src/Dropdown.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class Dropdown extends React.Component {
170170
focusNextOnOpen() {
171171
const menu = this.menu;
172172

173-
if (!menu.focusNext) {
173+
if (!menu || !menu.focusNext) {
174174
return;
175175
}
176176

test/NavbarBrandSpec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('<Navbar.Brand>', () => {
2020
it('Should create NavbarBrand A (link) element', () => {
2121
const instance = ReactTestUtils.renderIntoDocument(
2222
<NavbarBrand>
23-
<a href>BrandLink</a>
23+
<a href="">BrandLink</a>
2424
</NavbarBrand>
2525
);
2626

tools/babel-register.js

-3
This file was deleted.

tools/build-bower.js

-38
This file was deleted.

tools/build-dist.js

-74
This file was deleted.

tools/build-es.js

-14
This file was deleted.

tools/build-lib.js

-15
This file was deleted.

0 commit comments

Comments
 (0)