Showdown: Bundle size

Created on 1 Mar 2018  路  4Comments  路  Source: showdownjs/showdown

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?

enhancement

Most helpful comment

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.

All 4 comments

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.

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.

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.

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ifeltsweet picture ifeltsweet  路  6Comments

BusyHe picture BusyHe  路  4Comments

evanplaice picture evanplaice  路  3Comments

KirkMunro picture KirkMunro  路  6Comments

oscarmorrison picture oscarmorrison  路  4Comments