Skip to content
This repository was archived by the owner on Jan 16, 2019. It is now read-only.

Commit f25b5eb

Browse files
committed
Migrate webpack stuff
1 parent ee07a4c commit f25b5eb

19 files changed

+1376
-862
lines changed

.babelrc

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,45 @@
11
{
22
"presets": [
3-
"es2015",
3+
[
4+
"env",
5+
{
6+
"targets": {
7+
"browsers": [
8+
"last 2 versions",
9+
"iOS >= 9",
10+
"Safari >= 9",
11+
"not ie <= 11"
12+
],
13+
// We currently minify with uglify
14+
// Remove after https://github.com/mishoo/UglifyJS2/issues/448
15+
"uglify": true,
16+
},
17+
// Enable tree-shaking for webpack
18+
"modules": false,
19+
"useBuiltIns": true,
20+
}
21+
],
422
"react",
5-
"stage-0",
623
],
724
"env": {
825
"development": {
9-
"presets": [
10-
"react-hmre",
26+
"plugins": [
27+
"react-hot-loader/babel",
1128
],
1229
},
1330
"production": {
1431
"presets": [
1532
"react-optimize",
1633
],
1734
},
35+
"test": {
36+
"plugins": [
37+
"transform-es2015-modules-commonjs"
38+
],
39+
},
1840
},
1941
"plugins": [
20-
"syntax-object-rest-spread",
2142
"transform-object-rest-spread",
43+
"transform-class-properties",
2244
],
2345
}

.eslintrc.js

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ module.exports = {
55
'airbnb',
66
'plugin:flowtype/recommended',
77
],
8+
env: {
9+
browser: true,
10+
node: true,
11+
},
812
plugins: [
913
'flowtype',
10-
'react',
14+
'import',
1115
'jsx-a11y',
12-
'import'
16+
'react',
1317
],
1418
settings: {
1519
'import/resolver': {
@@ -18,43 +22,43 @@ module.exports = {
1822
},
1923
},
2024
},
21-
env: {
22-
'browser': true,
23-
'node': true,
24-
'es6': true,
25-
'mocha': true,
26-
'jest': true,
27-
},
2825
rules: {
29-
// Turning it on causes undecipherable errors.
26+
// Body style is more troublesome than it's worth
3027
'arrow-body-style': 'off',
31-
// Import required only for non-js files.
28+
// Consistent arrow parens.
29+
'arrow-parens': ['error', 'as-needed', { requireForBlockBody: true }],
30+
// After adding flowtypes the lines are getting longer.
31+
'max-len': ['error', 120],
3232
'import/extensions': ['error', 'always',
3333
{
3434
js: 'never',
35-
jsx: 'never',
36-
},
35+
jsx: 'never'
36+
}
3737
],
38-
// To allow flowtype definitions to be imported.
39-
'import/no-duplicates': 'error',
40-
// To allow enzyme to be imported in tests.
41-
'import/no-extraneous-dependencies': ['error', { 'devDependencies': ['**/*.test.js'] }],
42-
'import/no-named-as-default': 'off',
43-
'import/no-named-as-default-member': 'off',
44-
'jsx-a11y/href-no-hash': 'off',
45-
'jsx-a11y/no-static-element-interactions': 'off',
46-
'no-duplicate-imports': 'off',
47-
'no-underscore-dangle': ['error', { 'allowAfterThis': true, 'allowAfterSuper': true }],
48-
'react/jsx-filename-extension': 'off',
38+
'react/no-array-index-key': 'off',
39+
'react/jsx-closing-bracket-location': 'off',
4940
'react/jsx-first-prop-new-line': ['error', 'never'],
5041
// It just looks nicer without the space.
5142
'react/jsx-space-before-closing': 'off',
52-
// TODO: https://github.com/yannickcr/eslint-plugin-react/issues/861
43+
// SEE: https://github.com/yannickcr/eslint-plugin-react/issues
5344
'react/no-unused-prop-types': 'off',
54-
'react/jsx-tag-spacing': ['error', {
55-
beforeSelfClosing: 'never',
45+
// Enables typing to be placed above lifecycle
46+
"react/sort-comp": ['error', {
47+
order: [
48+
'type-annotations',
49+
'static-methods',
50+
'lifecycle',
51+
'/^on.+$/',
52+
'everything-else',
53+
'render',
54+
],
5655
}],
57-
// Let git handle the linebreaks instead
56+
'react/require-default-props': 'off',
57+
// TODO: Replace divs with buttons, but remove all button styling.
58+
'jsx-a11y/no-static-element-interactions': 'off',
59+
// TODO: Investigate this error.
60+
'jsx-a11y/href-no-hash': 'off',
61+
// Let git handle the linebreaks instead.
5862
'linebreak-style': 'off',
59-
}
60-
}
63+
},
64+
};

.flowconfig

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
[ignore]
2-
.*node_modules/babel-core.*
3-
.*node_modules/fbjs.*
4-
.*node_modules/stylelint.*
52
.*node_modules/.*
63

74
[include]
@@ -11,6 +8,4 @@
118
[options]
129
module.name_mapper='^\(actions\|components\|data\|middlewares\|reducers\|types\|utils\|views\)\/?\(.*\)$' -> '<PROJECT_ROOT>/src/js/\1/\2'
1310
module.name_mapper='^img\/\(.*\)$' -> '<PROJECT_ROOT>/src/img/\1'
14-
module.name_mapper.extension='css' -> '<PROJECT_ROOT>/__mocks__/cssStub.js.flow'
15-
module.name_mapper.extension='scss' -> '<PROJECT_ROOT>/__mocks__/cssStub.js.flow'
1611
suppress_comment= \\(.\\|\n\\)*\\$FlowFixMe

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ coverage
88

99
# dll
1010
dll
11+
.cache-loader
1112

1213
# production
1314
dist

flow-typed/package-dep-libdefs.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
// This file is autogenerated by flow-scripts.
22

3+
declare module 'babel-polyfill' {
4+
declare module.exports: any;
5+
}
6+
37
declare module 'react' {
48
declare module.exports: any;
59
}

package.json

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,38 @@
44
"description": "Barebones React Redux starter kit on Webpack",
55
"main": "index.js",
66
"scripts": {
7-
"start": "cross-env NODE_ENV=development webpack-dev-server --config=webpack/webpack.config.dev.js --open",
8-
"build": "cross-env NODE_ENV=production webpack --config=webpack/webpack.config.prod.js",
7+
"start": "cross-env NODE_ENV=development babel-node scripts/start",
8+
"build": "cross-env NODE_ENV=production babel-node scripts/build",
99
"build:dll": "cross-env NODE_ENV=development webpack --config=webpack/webpack.config.dll.js",
10-
"postinstall": "yarn run build:dll && flow-scripts stub",
10+
"postinstall": "npm run build:dll && flow-scripts stub",
11+
"flow": "flow check",
12+
"lint": "eslint test src/js/**/*.{js,jsx} webpack scripts",
13+
"lint:src": "eslint src/js/**/*.{js,jsx}",
14+
"lint:test": "eslint test",
15+
"lint:scripts": "eslint webpack scripts",
1116
"test": "jest --coverage",
12-
"test:watch": "jest --config .jestconfig --watch"
17+
"test:watch": "jest --watch",
18+
"ci": "npm run lint && npm run test && npm run build "
1319
},
1420
"author": "Tay Yang Shun",
1521
"license": "MIT",
1622
"devDependencies": {
1723
"autoprefixer": "^7.1.2",
24+
"babel-cli": "^6.24.1",
1825
"babel-core": "^6.25.0",
1926
"babel-eslint": "^7.2.3",
2027
"babel-loader": "^7.1.1",
21-
"babel-plugin-syntax-object-rest-spread": "^6.13.0",
22-
"babel-plugin-transform-es2015-destructuring": "^6.23.0",
28+
"babel-plugin-transform-class-properties": "^6.24.1",
2329
"babel-plugin-transform-object-rest-spread": "^6.23.0",
24-
"babel-preset-es2015": "^6.24.1",
30+
"babel-preset-env": "^1.5.2",
2531
"babel-preset-react": "^6.24.1",
26-
"babel-preset-react-hmre": "^1.1.1",
2732
"babel-preset-react-optimize": "^1.0.1",
28-
"babel-preset-stage-0": "^6.24.1",
33+
"babel-register": "^6.24.1",
34+
"cache-loader": "^1.0.3",
2935
"clean-webpack-plugin": "^0.1.16",
3036
"cross-env": "^5.0.1",
3137
"css-loader": "^0.28.4",
38+
"cssnano": "^3.10.0",
3239
"enzyme": "^2.9.1",
3340
"eslint": "^4.3.0",
3441
"eslint-config-airbnb": "^15.0.2",
@@ -38,29 +45,35 @@
3845
"eslint-plugin-import": "^2.7.0",
3946
"eslint-plugin-jsx-a11y": "^6.0.2",
4047
"eslint-plugin-react": "^7.1.0",
41-
"extract-text-webpack-plugin": "^3.0.0",
48+
"extract-text-webpack-plugin": "^2.1.2",
4249
"file-loader": "^0.11.2",
4350
"flow-bin": "^0.51.0",
4451
"flow-scripts": "^0.3.0",
4552
"flow-status-webpack-plugin": "^0.1.7",
4653
"html-webpack-plugin": "^2.29.0",
4754
"jest": "^20.0.4",
55+
"lodash-webpack-plugin": "^0.11.4",
4856
"node-sass": "^4.5.3",
57+
"optimize-css-assets-webpack-plugin": "^2.0.0",
4958
"postcss-loader": "^2.0.6",
5059
"react-addons-test-utils": "^15.6.0",
60+
"react-dev-utils": "^0.5.2",
61+
"react-hot-loader": "3.0.0-beta.7",
62+
"react-test-renderer": "^15.6.1",
5163
"redux-logger": "^3.0.6",
5264
"sass-loader": "^6.0.6",
5365
"style-loader": "^0.18.2",
5466
"stylelint": "^8.0.0",
5567
"stylelint-config-standard": "^17.0.0",
5668
"stylelint-webpack-plugin": "^0.9.0",
5769
"url-loader": "^0.5.9",
58-
"webpack": "^1.13.1",
59-
"webpack-dev-server": "^1.14.1",
70+
"webpack": "^2.7.0",
71+
"webpack-dev-server": "^2.6.1",
6072
"webpack-merge": "^4.1.0"
6173
},
6274
"dependencies": {
6375
"axios": "^0.16.2",
76+
"babel-polyfill": "^6.23.0",
6477
"bootstrap": "^4.0.0-alpha.6",
6578
"lodash": "^4.15.0",
6679
"react": "^15.6.1",
@@ -72,5 +85,11 @@
7285
"react-router-redux": "^4.0.8",
7386
"redux": "^3.7.2",
7487
"redux-thunk": "^2.2.0"
75-
}
88+
},
89+
"browserslist": [
90+
"last 2 versions",
91+
"iOS >= 9",
92+
"Safari >= 9",
93+
"not ie <= 11"
94+
]
7695
}

scripts/.eslintrc.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
rules: {
3+
// build scripts gotta print
4+
'no-console': 'off',
5+
// eslint thinks script dev dependencies are dependencies
6+
'import/no-extraneous-dependencies': 'off',
7+
},
8+
};

scripts/build.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
const chalk = require('chalk');
2+
const webpack = require('webpack');
3+
const { measureFileSizesBeforeBuild, printFileSizesAfterBuild } = require('react-dev-utils/FileSizeReporter');
4+
5+
const config = require('../webpack/webpack.config.prod');
6+
const parts = require('../webpack/webpack.parts');
7+
8+
// Print out errors
9+
function printErrors(summary, errors) {
10+
console.log(chalk.red(summary));
11+
console.log();
12+
errors.forEach((err) => {
13+
console.log(err.message || err);
14+
console.log();
15+
});
16+
}
17+
18+
// Create the production build and print the deployment instructions.
19+
function build(previousFileSizes) {
20+
console.log(chalk.cyan('Creating an optimized production build...'));
21+
console.log();
22+
23+
webpack(config).run((err, stats) => {
24+
if (err) {
25+
printErrors('Failed to compile.', [err]);
26+
process.exit(1);
27+
}
28+
29+
if (stats.compilation.errors.length) {
30+
printErrors('Failed to compile.', stats.compilation.errors);
31+
process.exit(1);
32+
}
33+
34+
if (process.env.CI && stats.compilation.warnings.length) {
35+
// eslint-disable-next-line max-len
36+
printErrors('Failed to compile. When process.env.CI = true, warnings are treated as failures. Most CI servers set this automatically.', stats.compilation.warnings);
37+
process.exit(1);
38+
}
39+
40+
console.log(chalk.green('Compiled successfully.'));
41+
console.log();
42+
43+
console.log('File sizes after gzip:');
44+
console.log();
45+
printFileSizesAfterBuild(stats, previousFileSizes);
46+
console.log();
47+
48+
console.log(`The ${chalk.cyan(parts.PATHS.build)} folder is ready to be deployed.`);
49+
});
50+
}
51+
52+
// First, read the current file sizes in build directory.
53+
// This lets us display how much they changed later.
54+
// First, read the current file sizes in build directory.
55+
// This lets us display how much they changed later.
56+
measureFileSizesBeforeBuild(parts.PATHS.build).then((previousFileSizes) => {
57+
// Start the webpack build
58+
build(previousFileSizes);
59+
});

0 commit comments

Comments
 (0)