-
Notifications
You must be signed in to change notification settings - Fork 260
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
Introduce Webpack #2230
Introduce Webpack #2230
Conversation
…umbsdown and share in the site itself
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are accessibility issues in these changes.
Thank you @user512 and @utsab! This is excellent work. I will discuss our review process with @SailingSteve at our next standup. I am excited to try it out myself! |
* This is to support Cordova development because Cordova developer have to do symlink when setting up project
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏 You fixed the issue(s)! Great work.
Note to self, would be nice to eliminate these:
|
HTTPS with WebPack
Works -- allows you to login with Twitter, but redirects back to localhost:3000, not to the tunnel -- that is fixable. Facebook does not immediately work. |
Approved after extensive review by @SailingSteve. 👍 |
Moved post merge bugs listing to #2465 |
What github.com/wevote/WebApp/issues does this fix?
#757
Changes included this pull request?
Purpose
The purpose of this pull request is to refactor the build process for WebApp. WebApp currently uses gulp + browserify to build the source files. The primary product of this build process is the single bundle.js file which contains the app’s main javascript logic. The problem is that it can take over 2 minutes to generate this file. Even a small change to one file means that we must wait 2 minutes for the entire bundle.js to rebuild. With webpack, we have reduced the build time down to less than 70 seconds (initial build) & 3 seconds (hot reload) (using weback’s hot-rebuilding capabilities).
Old build process vs. new build process
The old build process (gulp) was configured in Gulpfile.js which defined a series of "tasks" to build the finished assets. The new build process (webpack) is configured in webpack.config.js. We translated each gulp task into a corresponding webpack configuration as follows:
Gulp task: "browserify" ==> Generates the bundle.js
Webpack: Generates the bundle.js automatically
Gulp task: "server" ==> Start the express server
Webpack: Webpack starts up the server automatically.
Gulp task: "compile-bootstrap" & "sass" ==> Include the bootstrap scss libraries converted into css + compile other sass files into css
Webpack: bootstrap libraries are imported directly into main.scss
a300c74 ==> This commit fixes compile bootstrap.
https://github.com/utsab/WebApp/blob/f78c25aeeccf90ce714164f8dc2abb57fee50232/src/js/index.js#L11
This line imports
main.scss
directly into index.jsThe style-loader, css-loader, sass-loader loaders used in webpack.config.js -> import sass in js file, compile sass into css and inject a <style> tag
Gulp task: "lint-css"
Webpack: We did not configure webpack to run the css linter. There was some confusion about this one. It looks like the css linter is run as a git commit hook. The gulp lint-css watcher does not seem to do anything.
Gulp task: "clean:build" ==> clears out the build directory before rebuilding
Webpack: The CleanWebpackPlugin in webpack.config.js does the same
Gulp task: "copy-fonts" ==> move all fonts file into build/fonts
Webpack: file-loader ==> The file-loader resolves import/require() on a file into a url and emits the file into the output directory.
Gulp task: "copy-index" ==> copies the index.html from src to build
Webpack: Done by HtmlWebpackPlugin in webpack.config.js
Gulp task: "copy-css" ==> translates all the src/css/**/*.scss files into the build directory as css
Webpack: The scss files are imported directly into the relevant js files
Gulp task: "copy-img" ==> move all images into build/images
Webpack: Done by file-loader. images are now explicitly imported into the relevant js files (see example below)
Gulp task: "copy-javascript" ==> move all files in
src/javascript
intobuild/javascript
Webpack: Done by
copy-webpack-plugin
New ways to import images: Import images as variables and use variable in jsx See example: 7a1ce2a
Watchify is now replaced by Webpack hot reload
How to import image going forward (with example)
7a1ce2a
Build time comparison and hot reload time (with screenshot, benchmarking)
Initial build time with gulp:
WIth Webpack it's down to 76 seconds
Before webpack, one line changes would take > 1 minutes to rebuild
After webpack, one line changes would take < 5 seconds to rebuild
In other words, after making a change, webpack hot-rebuilds in 2.4 seconds whereas the old build process with gulp would have taken 84 seconds to rebuild. This represents a 35x improvement in build time.
Known issue: broken images and solution with reason not fixing at the moment
Note: since this project is moving fast and new images are added everyday, we can’t keep up with fixing all the images.
We fixed majority of the images and would like to recommend merging this in after some testing to ensure no major problem and we can patch newly added images.
Testing Cordova build
Follow this instruction to test Cordova build
https://github.com/wevote/WeVoteCordova#install-our-code-and-the-cordova-libraries
However on the symlink part, since we no longer have
fonts.
,css/
andjavascript/
, we just have to symlinkindex.html
,bundle.js
andimg/
.TO TEST
bundle.js
(See Cordova Build section below)Note: We have only tested in local environment, highly suggest testing on an AWS instance for close to production behavior.
Cordova Build
The webpack development build (
npm start
) generates abundle.js
that containseval
syntax for the purpose of speeding up the development build process. However, Cordova security policy will reject this development buildbundle.js
.We have tested that Cordova will work fine with webpack production build's
bundle.js
(npm run prod
).Google Analytic
The new webpack build process copy files from
src/javascript
tobuild/javascript
to mimic old Gulp build process behavior. However, when working on this pull request, we can never test if this has any negative impact on Google Analytic related feature. Highly suggest testing Google Analytic to ensure this is still working as expected.