Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev environment setup #2

Merged
merged 19 commits into from
Aug 10, 2018
Merged

Dev environment setup #2

merged 19 commits into from
Aug 10, 2018

Conversation

ynigoreyes
Copy link
Contributor

@ynigoreyes ynigoreyes commented Aug 6, 2018

So there were a lot of things to update and change. I was able to get webpack 4 going and it will build correctly for both production and development.

However, I am not able to get Flow or Jest working (and for some reason w0rp/Ale for vim).
Also, node-sass is a giant performance problem: webpack-contrib/sass-loader#531

Proposal

I was hoping we could use Create React App to bootstrap the project. We would most likey run it ejected after configuring jest, Flow, and Hot Reload so that we could alter the webpack configs like we are used to. After ejecting we should be able to add the absolute path configs from our current webpack scripts and everything should at the least compile. The tests will need some work to get working again, but they won't be broken, logic wise. Only configuration wise.

This saves us a lot of time and heartache in trying to figure out how to get jest and Flow running because it comes baked in. Also, there isn't a bunch of weird dependencies so bundle size will stay small if not get smaller since CRA already comes with uglifyication and compression, which solves TTUSDC/cpceed-webapp#34 and comes with polyfills to support the older browsers which solves TTUSDC/cpceed-webapp#39.

Actually, the bundle size will decrease dramatically. on my hackwestx app, i have antd and socket.io as dependencies, and my bundle size for that app is 155kb + 70kb for antd's css. Our bundle size right now is at 1.6 mb.

@ynigoreyes ynigoreyes requested a review from NilsG-S August 6, 2018 16:14
@NilsG-S
Copy link
Contributor

NilsG-S commented Aug 6, 2018

I don't have a problem with you starting over using CRA. The current project will require so many updates/cleanups that it may be cleaner to restart. As it is, we're probably dragging around unnecessary technical debt. How much of the original code will you be able to keep?

Is sass-loader even necessary for our current configuration? Material-UI uses JSS, so it doesn't seem unreasonable to think it might not be.

NilsG-S
NilsG-S previously requested changes Aug 6, 2018
Copy link
Contributor

@NilsG-S NilsG-S left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few small clarifications/changes

package.json Outdated
"webpack-dev-server": "2.4.1",
"webpack-merge": "3.0.0"
"webpack": "^4.16.4",
"webpack-cli": "^3.1.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically webpack-cli is installed globally, isn't it? It's a developer tool, not a dev dependency

package.json Outdated
"webpack-merge": "3.0.0"
"webpack": "^4.16.4",
"webpack-cli": "^3.1.0",
"webpack-dev-middleware": "^3.1.3",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

webpack-dev-server uses webpack-dev-middleware in an express server to do what it does. This should be unnecessary

Copy link
Contributor Author

@ynigoreyes ynigoreyes Aug 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the webpack set up will be replaced completely by CRA's so this will change all together

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I just wasn't sure whether you wanted to merge these changes in before integrating CRA

Copy link
Contributor Author

@ynigoreyes ynigoreyes Aug 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, i can start the integration now and submit another pull req when EVERYTHING is done. I just like to keep the merges incremental. Granted, going to CRA is definetly incremental... What's would you think is best?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incremental is definitely better. But if so, I would prefer you fix these nitpicks before I approve

package.json Outdated
"babel-preset-env": "1.7.0",
"babel-preset-flow": "6.23.0",
"babel-preset-react": "6.24.1",
"babel-preset-stage-2": "6.24.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this get us that env doesn't?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flow and arrow functions as methods in classes. This also allows us to set initial state outside of the constructor so that we don't have to use the constructor super boilerplate.

@@ -1,10 +1,11 @@
{
"presets": [
"es2015",
"react"
"env",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you typically have to pass some configuration options to env?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. Works out of the box

@@ -3,15 +3,16 @@ module.exports = {
"env": {
"mocha": true,
"node": true,
"browser": true,
"browser": true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol, you don't like commas on final lines? My linter typically does

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No i do like commas on the final lines, im just not sure as to why some did not have it to begin with. Usually it formats on save and fixes stuff like this but oops

}

handleRegister(data) {
state = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the preferred way of doing things these days? Moving state and binding out of the constructor, that is

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is

webpack/base.js Outdated
commonPath
]
commonPath,
testPath,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is just for Karma. From my recollection Jest has it's own module paths.

https://github.com/CodeSpaceHQ/telescreen/blob/master/sub-projects/hub/jest.server.js

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. and again, webpack will change all together

@ynigoreyes
Copy link
Contributor Author

well actually i will be able to keep ALL the code in src, test and common. The webpack config we have right now is going to have to be merged manually if not replaced completely.

@NilsG-S
Copy link
Contributor

NilsG-S commented Aug 6, 2018

Sounds good. Is there not some hot-reloading/flow support that has to be changed in the code?

@ynigoreyes
Copy link
Contributor Author

the flow set up is a quick install of flow-bin as a devDep and running Flow init. Hot Reloading set up is the same all around

@NilsG-S
Copy link
Contributor

NilsG-S commented Aug 6, 2018

So do you want me to wait until you finish adding CRA stuff to this PR?

@ynigoreyes
Copy link
Contributor Author

Yeah thats fine. I can start the migration now

@NilsG-S NilsG-S dismissed their stale review August 7, 2018 04:47

Significant changes

@ynigoreyes
Copy link
Contributor Author

So i didn't set up flow because it got really mad at me when we tried using the absolute paths that were set up with webpack. And what we had with PropTypes was working completely fine

@@ -111,10 +111,4 @@ NavBar.propTypes = {
logout: PropTypes.func.isRequired,
};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the linter got mad when we had a requiredProp along with a default value. If the user was not passed, then webpack would not compile altogether, so there was no need to add a default prop value

Copy link
Contributor

@NilsG-S NilsG-S left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good for the most part. There were a few things that occurred multiple times which I only commented on once. The exported functional components and accessing state in setState, from what I recall. Would you rather that I comment on each individual occurrence? It might make them easier to find.

.eslintignore Outdated
@@ -1 +1,4 @@
**/*{.,-}min.js
/public
/config/**
registerServiceWorker.js
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there something about service workers that eslint disagrees with?

Copy link
Contributor Author

@ynigoreyes ynigoreyes Aug 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, lines 2 and 3 are not needed anymore. The service worker is all over the place. It'm mainly so serve content offline. That is all is seems to do but that boilerplate from CRA. However, it is not styled in any way really, but i don't want to touch it since it is boilerplate from CRA

build/*.json
build/*.js
# production
/build
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be public now, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well actually you want to version the public folder because that contains you index.html and the service worker. CRA builds from the public folder into the build folder. Yeah it through me off the first time too

@@ -0,0 +1,7 @@
const rewireReactHotLoader = require('react-app-rewire-hot-loader')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need react-app-rewired at the moment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, for stateful hot reloading in the development env

package.json Outdated
"babel-preset-env": "1.7.0",
"babel-preset-stage-2": "6.24.1",
"chai": "4.1.2",
"cross-env": "^5.2.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need cross-env at this point?

Copy link
Contributor Author

@ynigoreyes ynigoreyes Aug 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No we do not, removing now

<meta charset="utf-8">
<!-- Google Styling -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you doing CDN only, or are you also planning to host the files?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I'm just going to use CDN only, just to keep bundle small, is there any good reason why we should host it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a big deal. For our purposes this should be fine. If you're concerned that the CDN might go down at some point in the future, it's nice to have self-hosted files as a backup.

@@ -0,0 +1,15 @@
{
"short_name": "React App",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably change these

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


describe('Auth.jsx', () => {
it('Changes tabs', () => {
const authTest = shallow(<Auth authCancelled={() => {}} />);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This spacing looks kinda weird

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

// Use the navigate and logout props

// TODO: Render the auth view in a modal instead
export const MenuButton = (props) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these need to be exported?

toggleAuth: PropTypes.func.isRequired,
};

const styles = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should consider putting styles in a different file. It's not a big deal here, but I've seen style objects get really big. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well i mean I really don't want to make a whole other file for this one in particular. Most of the styling is done by the component library so to make a new file for maybe 5 lines of uncondensed style might just be clutter. For the Content and Body of the pages, we should make a styles object in a different file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good

toggleAuth = () => {
this.setState({
...this.state,
auth: !this.state.auth,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this violate no-access-state-in-setstate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does, but i fixed it

package.json Outdated
@@ -59,6 +59,7 @@
},
"jest": {
"setupTestFrameworkScriptFile": "./src/setupTest.js",
"testEnvironment": "node",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason, Jest is running really slow. Supposedly this speeds it up?

@@ -12,7 +12,7 @@ import MenuItem from '@material-ui/core/MenuItem';
import Menu from '@material-ui/core/Menu';

import { ModalView } from 'components/';
import AuthContainer from 'layout/Auth';
import AuthContainer from 'components/Auth';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved it to components since we reuse this component

@ynigoreyes ynigoreyes merged commit 2a86bc8 into master Aug 10, 2018
@ynigoreyes ynigoreyes deleted the dev-environment-setup branch August 13, 2018 01:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants