-
Notifications
You must be signed in to change notification settings - Fork 438
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
[MAJOR] js: Move to webpack, pug from r.js, jade #800
Conversation
Pinging @stefangehn, @blatinier, @Lucas-C and anyone else interested in moving this project forward. |
I've created a package for easier testing: |
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.
This is great!
Awesome job on moving everything to ES6 modules & webpack
O.O
Maybe this should be merged as part of #801 as we would have the added confidence of the new tests?
Thank you for reviewing! Those questions you asked were all obstacles I stumbled upon while porting and was kind of too lazy to document. Thanks for keeping me honest ;) I'll document as I have written in individual responses inline.
While waiting for the test suite to be adequate might sound like a sensible strategy for keeping bugs out, it'll also mean keeping up a massive amount of rebase work and effectively blocking any contribs to the client (or doing a lot of merge conflict work). So I'll be selfish and merge this |
eae2a02
to
1590e46
Compare
This makes it easier to debug when testing. The demo shouldn't be user-facing, but either way, the performance penalty should be outweighed by debugging benefits.
In the interest of maintainability and integration with other testing tools, get rid of `RequireJS` (sometimes also called `r.js` or `requirejs`) This necessitates the following changes: - Removing the `almond` (`AMD`) module loader (superseded by webpack internals) - Removing `requirejs-text` for loading static resources (superseded by webpack `asset/source` loader) - Removing `jade` templating engine (superseded by `pug`, which represents the original `jade` project that had to be renamed due to trademark issues) `pug` v2+ no longer accepts `'mystr-{#foo.bar}'`-style variables inside attributes, so `*.pug` templates need to be changed accordingly (`mystr' + foo.bar`) Note: templates have been moved to `templates/` directory and renamed from `.jade` to `.pug`. - `jade-runtime` and accompanying shims (superseded by simply `pug-runtime`) - Move `.svg` files inside own dir, simplify loading via `webpack`'s `asset/source` - Add `webpack` config - Add build scripts to `package.json` - Adjust `Makefile` to use `webpack` via `npm run` - Emit JS source map files from `webpack` (eases debugging) - `.gitignore` JS source map files While RequireJS utilized the following syntax: ``` define(["app/foo"], function(foo) { var bar = doSomeStuff... return bar; }) ``` Jest and other testing libraries need the NodeJS standard `CommonJS` style: ``` const foo = require("app/foo"); var bar = doSomeStuff... module.exports = { bar }; ``` Note: ES6/ECMAScript2015-style `import` has not been used since it would need transpilation via e.g. `babel` to be understood by Jest. The RequireJS-style wrapping of all code inside `define({...})` caused everything to be indented by at least one level. To keep the changes in this commit manageable, indentation will be removed in a later commit.
Since switching from RequireJS to CommonJS syntax, the `define()` wrapper is no longer needed and as such, the the code formerly inside parentheses can be de-indented by one level.
Introduction
As already discussed in #754, try to make Isso more maintainable by facilitating modern testing practices.
This PR is a bit massive, but trying to make
pug
or other updated deps play nice with RequireJs just for the sake of a clean history is not something I'm prepared to do.So, here goes:
js: Move to webpack, pug from r.js, jade
In the interest of maintainability and integration with other testing tools, get rid of
RequireJS
(sometimes also calledr.js
orrequirejs
)This necessitates the following changes:
almond
(AMD
) module loader (superseded by webpack internals)requirejs-text
for loading static resources (superseded by webpackasset/source
loader)jade
templating engine (superseded bypug
, which represents the originaljade
project that had to be renamed due to trademark issues)pug
v2+ no longer accepts'mystr-{#foo.bar}'
-style variables inside attributes, so*.pug
templates need to be changed accordingly (mystr' + foo.bar
)Note: templates have been moved to
templates/
directory and renamed from.jade
to.pug
.jade-runtime
and accompanying shims (superseded by simplypug-runtime
).svg
files inside own dir, simplify loading viawebpack
'sasset/source
webpack
configpackage.json
Makefile
to usewebpack
vianpm run
webpack
(eases debugging).gitignore
JS source map filesWhile RequireJS utilized the following syntax:
Jest and other testing libraries need the NodeJS standard
CommonJS
style:Note: ES6/ECMAScript2015-style
import
has not been used since it would need transpilation via e.g.babel
to be understood by Jest.The RequireJS-style wrapping of all code inside
define({...})
caused everything to be indented by at least one level.To keep the changes in this commit manageable, indentation will be removed in a later commit.
isso: js: treewide: De-indent one level
Since switching from RequireJS to CommonJS syntax, the
define()
wrapper is no longer needed and as such, the the code formerly inside parentheses can be de-indented by one level.isso: js: i18: RequireJS to module.exports
(Just an extension of previous commit, to avoid touching too many files at once)
demo: Use dev version of embed.js
This makes it easier to debug when testing. The demo shouldn't be user-facing, but either way, the performance penalty should be outweighed by debugging benefits.
isso: js: Reduce deps for app/lib/
(Just a minor commit to make the following unit tests easier)
Verifying
You can verify this commit by checking out this PR:
git clone https://github.com/posativ/isso isso cd isso/ git fetch origin pull/800/head:pull-800 git checkout pull-800
And then installing everything as documented in docs: Install from Source.
Then, either embed Isso into your site or use the demo at localhost:8080/demo
A note for people from the future: You can use
git blame --ignore-rev=<sha>
to "ignore" the de-indent commits. See A better git blame.Note to myself: We can probably ditch the templates altogether and simply use plain html with javascript string interpolation. That way, we lose
pug
,pug-loader
andpug-runtime
, which would make the bundle significantly smaller.