-
-
Notifications
You must be signed in to change notification settings - Fork 235
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
Move to ES6, Rollup bundler for ESM/CJS bundles #128
Conversation
@Pomax I wanted to know if you were okay with some of the changes, specifically ESLint & Rollup? |
There should not be any need for babel, if we're redoing this as proper ES6 code: adding a |
@@ -11,11 +11,11 @@ or read the souce (`./lib` for the library code, start at `index.js`). | |||
|
|||
## Use | |||
|
|||
`var Bezier = require('bezier-js')` and off you go. | |||
`const { Bezier } = require('bezier-js')` and off you go. |
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 should definitely be import { Bezier } from "bezier-js";
now =)
|
||
## Use in the browser | ||
|
||
Load the toplevel `bezier.js` the same way you would any other browser script, using a `<script src="..."></script>` declaration. | ||
Load `dist/bezier.js` the same way you would any other browser script, using a `<script src="..."></script>` declaration. |
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.
and this should probably no longer be necessary, if we're using proper ES6 (both the browser and node supposed es modules)
"browserify": "^9.0.3", | ||
"chai": "^3.2.0", | ||
"chai-stats": "^0.3.0", | ||
"eslint": "^7.6.0", |
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.
Let's use prettier
rather than eslint
. I'd rather have an opinionated but zero-conf linter than a free form linter that requires its own .rc file to do something sensible.
"webpack": "^1.12.13" | ||
"rollup": "^2.23.0", | ||
"rollup-plugin-sourcemaps": "^0.6.2", | ||
"rollup-plugin-terser": "^6.1.0" |
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.
no need to preemptively minify: if folks need minification, that would be a step their own config takes care of. Preemptive minification can in fact lead to worse results.
"uglify-js": "^2.4.17", | ||
"webpack": "^1.12.13" | ||
"rollup": "^2.23.0", | ||
"rollup-plugin-sourcemaps": "^0.6.2", |
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.
I honestly don't see much value in adding this: you don't minify code in your dev environment, so you don't need sourcemaps there, and prod should never load insanely huge debug-only files by default, so while an interesting idea, let's not add source mapping.
@@ -3,33 +3,33 @@ | |||
* and full commands, rather than relative coordinates | |||
* and/or shortcut commands. | |||
*/ | |||
function normalizePath(d) { | |||
export function normalisePath (d) { |
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 a singleton file, exposing a single function: this can be a default export.
export function normalisePath (d) { | |
export default function normalisePath (d) { |
@@ -1,33 +1,33 @@ | |||
var normalise = require("./normalise-svg.js"); | |||
import { normalisePath as normalise } from './normalise-svg'; |
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.
with the export made a default, this can just "stay" what it was:
import { normalisePath as normalise } from './normalise-svg'; | |
import normalise from './normalise-svg'; |
var term; | ||
var matcher = new RegExp('[MLCQZ]', ''); | ||
var segment; | ||
var values; | ||
var segments = []; | ||
var ARGS = { C: 6, Q: 4, L: 2, M: 2 }; |
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.
ES6 should not be using var
? ;)
import { Bezier } from './Bezier'; | ||
|
||
// math-inlining. | ||
const abs = Math.abs; |
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.
Again, ES6 is better than ES5 here.
const { abs, cos, sin, etc, etc } = Math;
var utils = Bezier.getUtils(); | ||
var assert = require("chai").use(require("chai-stats")).assert; | ||
|
||
const Bezier = require('../lib/bezier'); |
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 should definitely also become normal ES6 module code.
I think we need to restart this but on a different footing. If bezier.js gets uplifted to ES6, then that should be fully committed to: no more Let's restart this but do this in steps:
|
I'll redo this then I guess ;) |
Just remember to not "do everything": do step 1, file a PR, let's get that merged into https://github.com/Pomax/bezierjs/tree/es6 (I created a new branch for us to work against). Then we can iteratively improve that without ending up with one giant PR that is impossible to easily review =) "Write small changes, file a PR, land the PR, write more small changes" is infinitely better than "write large changes, discover something fundamental invalidates all the work" ^_^;; |
Changes