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

Custom bundle script details #5527

Merged
merged 24 commits into from
Mar 2, 2021
Merged

Custom bundle script details #5527

merged 24 commits into from
Mar 2, 2021

Conversation

archmoj
Copy link
Contributor

@archmoj archmoj commented Feb 25, 2021

PR to resolve #5521.

Here is how the syntax looks like.

npm run partial-bundle -- \
  --traces sunburst,treemap \
  --transforms filter,sort \
  --out customBundleName

Please note that scatter trace would always be added as it is located in lib/core.js not in lib/index.js.

Also one could use --unminified option to create unminified bundles.

@plotly/plotly_js

@archmoj archmoj added this to the NEXT milestone Feb 25, 2021
@nicolaskruchten
Copy link
Contributor

I wonder if a better default wouldn't be minified+sourcemaps, and then a single flag to do unminified+no_sourcemaps... Or maybe we always output all three?

 - include all traces, transforms and calendars by default
 - minify by default
@archmoj
Copy link
Contributor Author

archmoj commented Feb 26, 2021

I wonder if a better default wouldn't be minified+sourcemaps, and then a single flag to do unminified+no_sourcemaps... Or maybe we always output all three?

In ca4d557 the default is changed to minified.
But enabling sourcemaps by default can significantly increase the size (3X for scatter only bundle); so I still think it should not be the default. Also to mention having sourcemaps false and --nosurcemaps does not look great.

@nicolaskruchten
Copy link
Contributor

sourcemaps should not increase the bundle size... sourcemaps should appear in a separate file next to the bundle, right?

@archmoj
Copy link
Contributor Author

archmoj commented Feb 26, 2021

sourcemaps should not increase the bundle size... sourcemaps should appear in a separate file next to the bundle, right?

Right now it is included in the bundle.

@archmoj
Copy link
Contributor Author

archmoj commented Feb 26, 2021

sourcemaps should not increase the bundle size... sourcemaps should appear in a separate file next to the bundle, right?

Right now it is included in the bundle.

Maybe we should try this: browserify/browserify#339

@nicolaskruchten
Copy link
Contributor

Right now it is included in the bundle.

Let's definitely not do that :) Ideally sourcemaps are just another file on the side, that is only loaded by dev tools, and otherwise ignored by regular users.

@archmoj
Copy link
Contributor Author

archmoj commented Feb 26, 2021

Right now it is included in the bundle.

Let's definitely not do that :) Ideally sourcemaps are just another file on the side, that is only loaded by dev tools, and otherwise ignored by regular users.

It appears achieving that with browserify can complicate our build process even more.

@nicolaskruchten
Copy link
Contributor

Hmmm that's quite disappointing. Are you sure? this is a very standard way of using sourcemaps... If they must be inlined and therefore bloat the minified bundle, there'd be no point in minifying :)

@alexcjohnson
Copy link
Collaborator

I don't know if this is what you mean by "complicate our build process even more" - at least on the command line it seems straightforward

https://github.com/browserify/browserify-handbook#exorcist

var out = args.out ? args.out : 'custom';
var traces = inputArray(args.traces, allTraces);
var transforms = inputArray(args.transforms, allTransforms);
var calendars = inputBoolean(args.calendars, true);
Copy link
Collaborator

Choose a reason for hiding this comment

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

presumably at some point we will make more of the components registered in core optional. In order to support this in a backward-compatible way, perhaps we can make an option like skipcomponents=calendars, to later expand to allow skipping other components?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also thought about this a bit. But I think another option that we want to provide in future is which calendar(s) to add. That can explain why calendars logic here is quite similar to transforms and traces. For the moment it is handled by a boolean; but it could be expanded to a list.
Perhaps to avoid confusion we can move calendars code from ./components/calendars to ./calendars now or once we split it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

As discussed on slack, for now let's drop the calendars option - always include calendars in every bundle - until we can ensure that unrelated functionality like connectgaps will not break as in #4883.

At ~81kB minified and rarely used, it would be very nice to make these optional eventually, and you're right to want flexibility even when world calendars are requested to only include the necessary ones, not all of them

@alexcjohnson
Copy link
Collaborator

If we can get the source map in a separate file, then yes minified with source map should be the default. At that point I don't see a reason you'd want to invert either of those options (for dash and dash components that's all we provide), but I also don't see much harm keeping them.

@archmoj
Copy link
Contributor Author

archmoj commented Mar 1, 2021

I don't know if this is what you mean by "complicate our build process even more" - at least on the command line it seems straightforward

https://github.com/browserify/browserify-handbook#exorcist

Nice find. I was looking at other npm modules actually. BTW exorcist uses an old version of minimist which should be patched to avoid npm audit security warning. So I opened an issue here.

@archmoj archmoj requested a review from alexcjohnson March 1, 2021 17:52
if(sourceMap) {
bundleStream
.pipe(applyDerequire())
.pipe(exorcist(sourceMap))
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is generating the sourcemap of the unminified bundle. The real value is in a sourcemap of the minified bundle (which, for clarity, gets extension .min.js.map), then you never need the unminified bundle.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call. Addressed in 7d0145a.

@archmoj
Copy link
Contributor Author

archmoj commented Mar 1, 2021

FYI - thlorenz/exorcist#47

if(unminified) {
opts.dist = path.join(constants.pathToDist, 'plotly-' + out + '.js');
} else {
opts.distMin = path.join(constants.pathToDist, 'plotly-' + out + '.min.js');
Copy link
Contributor Author

@archmoj archmoj Mar 2, 2021

Choose a reason for hiding this comment

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

To avoid name conflicts (let's say one uses e.g. basic in output name with different traces), wondering instead of plotly-* shouldn't we use plotly_* here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

On the other hand folks making custom bundles will likely be used to our partial bundles already, so may be tripped up by the switch from - to _. Let's keep -, these bundles won't be published anyway.

new RegExp(
WHITESPACE_BEFORE +
'require\\(\'\\./' + t + '\'\\)' +
(t === 'calendars' ? '' : ','), // there is no comma after calendars require
Copy link
Collaborator

Choose a reason for hiding this comment

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

Feels a bit fragile - can we either just make the comma optional in the pattern, or add the comma in lib/index so all the lines are equivalent?

Copy link
Collaborator

@alexcjohnson alexcjohnson left a comment

Choose a reason for hiding this comment

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

💃 LGTM! Just one nonblocking comment remaining re: the regexp comma.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature something new
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CLI details for custom bundle script
3 participants