-
Notifications
You must be signed in to change notification settings - Fork 280
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
ADD: Webpack module bundler to compile code from /src/ to /dist/ #512
ADD: Webpack module bundler to compile code from /src/ to /dist/ #512
Conversation
OMGGGGGGG this is so awesome!!!! Ok, this is a big one. We'll want to be careful, and it may take some time to be thorough. AMAZING WORK @VladimirMikulic !!!!! 🎉 |
And noting Sasha is offline and not available right away! |
I changed the title to be more detailed, i hope it's correct: Also, let's start working on getting the above description in as readable a form as possible into the README file? |
Correct, you can use either require('module') or import 'module'. |
Wow awesome 🎉 🎉 |
@jywarren Alright, I updated the README to show project set up with Webpack. Maybe I can write a separate file like WEBPACK.md where I explain every single line of the configuration file? It would be for core project maintainers. What do you think? |
sure, that sounds nice! Just be sure to link to it from the README so it's
easy to find!
…On Tue, Jan 7, 2020 at 2:58 PM Vladimir Mikulic ***@***.***> wrote:
@jywarren <https://github.com/jywarren> Alright, I update the README to
show project set up with Webpack.
This is for average contributors. They don't need to know the inner
working of webpack.config.js.
Maybe I can write a separate file like WEBPACK.md where I explain every
single line of the configuration file? It would be for core project
maintainers.
What do you think?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#512?email_source=notifications&email_token=AAAF6J7KIKSX72TP4W5IJC3Q4TNGHA5CNFSM4KD5LM52YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEIKCRBI#issuecomment-571746437>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAF6J3OKKHRAZYBTAEPEEDQ4TNGHANCNFSM4KD5LM5Q>
.
|
@jywarren I've documented Webpack configuration file. It should be understandable now :) |
will go through this asap! |
@VladimirMikulic maybe rebuild that dist file and add it? Then if @sashadev-sky approves we can merge 🎉 |
Hi @sashadev-sky - no rush, but if you happen to have a moment to read this through it's really big and would be great to merge before too many other PRs! |
Let's do this 😄 |
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.
Thanks this is great - really appreciate you working through all the webpack configs here.
I made some change requests and besides those:
- Is it possible to enable running the tests during development as well? I think they are super helpful!
- Is it possible to make it so that the user doesn't have to run
$ npm run build
after changes? I think a lot of people will forget and commit their dist file unminified. Maybe a pre-commit hook? - I think webpack is meant to be integrated with either grunt or npm scripts, not both? Is it possible to shift to one of those directions? (Don't worry about the
$ grunt icons
task just referring to the build, server, tests, linting)
@sashadev-sky thank you very much for taking time to review this.
Yes, it is, but then we would sacrifice our Webpack development server. In my opinion, running tests on every minor change is just adding overhead. After the developer finishes the work, he runs One possible workaround to keep both would be to return the
Pre-commit hook would be awesome 👍 I'll add it.
Not really, it depends on the project. NPM scripts serves as an interface for easier management of our project. If you take a look at my If we were to rewrite it to stay in Gruntfile.js, we would have to use 3rd party plugin and it wouldn't be as clean as it is now. I've integrated Webpack with Grunt because it's not possible to go with Webpack-only approach in our project. They are different things built for different purposes. For example, JSHint is not supported in Webpack. We would need to adjust the coverage as well (if it's even possible). I hope this clears your doubts. Thanks a lot! |
I wonder, would it be possible to have a variant command which allows running both at one if you want? I know everyone has a slightly different workflow. Thanks, both of you!! |
@jywarren, unfortunately, it's not possible. I can get rid of WDS if you'd prefer that approach. |
Its no problem let's do it! @VladimirMikulic |
Up to this point, we have been writing old ES5. This change introduces Webpack, Webpack development server, Babel... From now on, we will be able to write modern JavaScript. Resolves #372
"Contributing" section updated to show project setup with Webpack.
The documentation for the Webpack configuration file can be found in WEBPACK.md
Added to resolve merge conflict.
Fixed redundant spaces and a grammar issue.
Changes: - Add npm build script to pre-commit task - Remove redundant Grunt's "default" task - Empty line to .gitignore - Move vendor.css to load before our css - Change WDS port from 3000 to 8080 - Update README.md
Co-Authored-By: Sasha Boginsky <41092741+sashadev-sky@users.noreply.github.com>
Co-Authored-By: Sasha Boginsky <41092741+sashadev-sky@users.noreply.github.com>
Co-Authored-By: Sasha Boginsky <41092741+sashadev-sky@users.noreply.github.com>
Co-Authored-By: Sasha Boginsky <41092741+sashadev-sky@users.noreply.github.com>
Co-Authored-By: Sasha Boginsky <41092741+sashadev-sky@users.noreply.github.com>
Karma configuration modified to generate the coverage folder inside of the working directory and without PhantomJS subfolder. Minor change: browserlist update to include browsers with the usage > 0.2% Resolves #537
@sashadev-sky no worries. The configuration has been updated properly :) |
ok lets do this!!! |
🚀 🚀 🎉 🎉 |
Congrats on GCI!!!! Great work |
Thanks a lot @sashadev-sky. It's been a pleasure to work with you :) |
you too! Published this on npm |
Wow this is thrilling! Amazing work folks! cc @rexagod as this is now ready for some portions of es6 upgrades due to webpack usage. |
Oops actually #312 |
Thanks, @jywarren. We did it :) |
* ADD: Webpack module bundler Up to this point, we have been writing old ES5. This change introduces Webpack, Webpack development server, Babel... From now on, we will be able to write modern JavaScript. Resolves #372 * UPDATE: README "Contributing" section "Contributing" section updated to show project setup with Webpack. * ADD: Webpack config file documentation The documentation for the Webpack configuration file can be found in WEBPACK.md * ADD: "npm run build" to travis.yml * ADD: leaflet.distortableimage.js to git tracker Added to resolve merge conflict. * UPDATE: Webpack.md Fixed redundant spaces and a grammar issue. * UPDATE: Project configuration files Changes: - Add npm build script to pre-commit task - Remove redundant Grunt's "default" task - Empty line to .gitignore - Move vendor.css to load before our css - Change WDS port from 3000 to 8080 - Update README.md * ADD: "watch" Grunt task to run tests on change * Update README.md Co-Authored-By: Sasha Boginsky <41092741+sashadev-sky@users.noreply.github.com> * Update README.md Co-Authored-By: Sasha Boginsky <41092741+sashadev-sky@users.noreply.github.com> * Update README.md Co-Authored-By: Sasha Boginsky <41092741+sashadev-sky@users.noreply.github.com> * Update WEBPACK.md Co-Authored-By: Sasha Boginsky <41092741+sashadev-sky@users.noreply.github.com> * Update README.md Co-Authored-By: Sasha Boginsky <41092741+sashadev-sky@users.noreply.github.com> * v0.12.6 🚀🚀🚀 * FIX: Karma tests coverage Karma configuration modified to generate the coverage folder inside of the working directory and without PhantomJS subfolder. Minor change: browserlist update to include browsers with the usage > 0.2% Resolves #537 * Rebase the branch Co-authored-by: Sasha Boginsky <41092741+sashadev-sky@users.noreply.github.com>
…liclab#512) * ADD: Webpack module bundler Up to this point, we have been writing old ES5. This change introduces Webpack, Webpack development server, Babel... From now on, we will be able to write modern JavaScript. Resolves publiclab#372 * UPDATE: README "Contributing" section "Contributing" section updated to show project setup with Webpack. * ADD: Webpack config file documentation The documentation for the Webpack configuration file can be found in WEBPACK.md * ADD: "npm run build" to travis.yml * ADD: leaflet.distortableimage.js to git tracker Added to resolve merge conflict. * UPDATE: Webpack.md Fixed redundant spaces and a grammar issue. * UPDATE: Project configuration files Changes: - Add npm build script to pre-commit task - Remove redundant Grunt's "default" task - Empty line to .gitignore - Move vendor.css to load before our css - Change WDS port from 3000 to 8080 - Update README.md * ADD: "watch" Grunt task to run tests on change * Update README.md Co-Authored-By: Sasha Boginsky <41092741+sashadev-sky@users.noreply.github.com> * Update README.md Co-Authored-By: Sasha Boginsky <41092741+sashadev-sky@users.noreply.github.com> * Update README.md Co-Authored-By: Sasha Boginsky <41092741+sashadev-sky@users.noreply.github.com> * Update WEBPACK.md Co-Authored-By: Sasha Boginsky <41092741+sashadev-sky@users.noreply.github.com> * Update README.md Co-Authored-By: Sasha Boginsky <41092741+sashadev-sky@users.noreply.github.com> * v0.12.6 🚀🚀🚀 * FIX: Karma tests coverage Karma configuration modified to generate the coverage folder inside of the working directory and without PhantomJS subfolder. Minor change: browserlist update to include browsers with the usage > 0.2% Resolves publiclab#537 * Rebase the branch Co-authored-by: Sasha Boginsky <41092741+sashadev-sky@users.noreply.github.com>
Up to this point, we have been writing old ES5.
This change introduces Webpack, Webpack development server, Babel...
From now on, we will be able to write modern JavaScript.
I know this is a game-changer for the project, so I'll do my best to explain what I did.
Webpack 🎉 🎉 🎉
Let's start from NPM scripts:
build
NPM scriptThe script uses
cross-env
package to setNODE_ENV
environment variable.It's cross-platform environment variables setter.
The
NODE_ENV
variable is used by Webpack to determine how it should bundle files.Webpack has 2 modes:
In the production mode, it will minify JS, do various optimizations...
In the development mode, it won't do that many optimizations because it would slow down our Webpack development server. That's why it's called development mode.
By running this script, your JS is ready to be deployed.
I removed leaflet.distortableimage.js from the git tracker. Should I add it back?
dev
NPM scriptThe script runs the
build
script and starts a Webpack development server, which opens examples/index.html file in the browser.We run
build
script first because it produces vendor.js & vendor.css files.The files contain 3rd party JS and CSS.
Previously, we included a bunch of
script
andlink
tags, now it's all bundled in these 2 files.(webpack.config.js:72 MergeIntoSingleFilePlugin)
Grunt
In the Gruntfile.js Webpack is loaded. It is used by
build
script(grunt build
).The
watch
task has been removed in favour of Webpack development server, which is much more flexible.Karma
In karma.conf.js, I've introduced
karma-babel-preprocessor
. As the name suggests it will transpile our ESNext to ES5, so Karma can run our tests.webpack.config.js
The
if
statement executes if we are running Webpack in the production mode.Including these plugins from the
if
statement directly inplugins
key on theconfig
object doesn't make sense. It drastically slows down our server(2s+ reload time!) and these are the files fromnode_modules
, we don't modify them :)If something is unclear, feel free to ask.
It took me quite a bit of time and research and hopefully it'll benefit the project in the long run 👍
We can also copy this file to other PublicLab projects and properly adjust it. 📝
Everyone should enjoy the beauty of ESNext 😄
Resolves #372
@cesswairimu @jywarren @sashadev-sky could you review this? Thanks.