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

Bundle size #504

Closed
jonaskello opened this issue Mar 1, 2018 · 4 comments
Closed

Bundle size #504

jonaskello opened this issue Mar 1, 2018 · 4 comments
Assignees

Comments

@jonaskello
Copy link

jonaskello commented Mar 1, 2018

First of all, thanks for this package!

I bundle it with webpack and it is currently the largest package in my bundle. The file dist/showdown.js is about 169K. However there is also dist/showdown.min.js which is only 97K so this is very nice! The problem is that webpack will include the one pointed to by the main field in package.json which is dist/showdown.js.

For react I get their minified dist so I looked at how they do it. They point their main field to a index.js that looks like this:

'use strict';

if (process.env.NODE_ENV === 'production') {
  module.exports = require('./cjs/react.production.min.js');
} else {
  module.exports = require('./cjs/react.development.js');
}

This causes webpack to use the minified version of react for production. Since showdown already have a minified version I think it would be simple to implement the same technique to get the minified version into webpack. So I would suggest to create an index.js file like this for showdown and point to it in the package.json main:

'use strict';

if (process.env.NODE_ENV === 'production') {
  module.exports = require('./dist/showdown.min.js');
} else {
  module.exports = require('./dist/showdown.js');
}

Not sure if it will do better than webpack running uglify on the unminified version but at least it cannot hurt to have it this way?

@stupidpupil
Copy link

stupidpupil commented Mar 15, 2018

You might also want to be aware that roughly 50-66% (depending on compression) of the minimised file is emoji. See this comment for more details, and how to strip them out if you're not going to use that feature.

@jonaskello
Copy link
Author

Thanks, that is good to know. I am not using that feature. Replacing in the source seems like kind of a hack. Would be nice if there was some more offical way to do it.

@tivie tivie self-assigned this May 7, 2018
@tivie
Copy link
Member

tivie commented May 7, 2018

This will be fixed in the next release (that, hopefully, will be v 2.0.0-alpha1)

The custom emojis were an interesting idea, but will be removed alltogether since they increase the size of the package by a lot.

@obedm503
Copy link

obedm503 commented May 7, 2018

I'd be nice if it was possible to register extra features as extensions, for example GMF, and emojis. They would be packaged but not bundled. The user would simply import the extension and register them. This would also simplify configuration when it comes to GMF

tivie referenced this issue Sep 14, 2018
* fix showdown emoji compression

* test: fix functional test
@tivie tivie closed this as completed Sep 14, 2018
iensu added a commit to iensu/showdown that referenced this issue Sep 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants