landakram / remark-wiki-link

Parse and render wiki links.
MIT License
90 stars 15 forks source link

Use a default export instead of named #17

Closed mdcfe closed 3 years ago

mdcfe commented 3 years ago

This PR changes src/index.js to use a default export instead of a named export. As noted in #12 this seems to be common behaviour for remark plugins, and I personally found this change was necessary to use this package with nuxt-content (https://github.com/landakram/remark-wiki-link/issues/12#issuecomment-813043538), which assumes that the given plugin uses default exports.

I notice rollup doesn't fail but gives this warning when building. The option it suggests suppresses the warning, but I'm not sure whether this is the best way to address this issue.

src/index.js → dist/index.cjs.js, dist/index.esm.js...
(!) Entry module "src\index.js" is implicitly using "default" export mode, which means for CommonJS output that its default export is assigned to "module.exports". For many 
tools, such CommonJS output will not be interchangeable with the original ES module. If this is intended, explicitly set "output.exports" to either "auto" or "default", otherwise you might want to consider changing the signature of "src\index.js" to use named exports only.
https://rollupjs.org/guide/en/#outputexports
src\index.js
created dist/index.cjs.js, dist/index.esm.js in 30ms

I realise this is a breaking change, as any import lines will change. I've left the package.json version as-is to be bumped after merge.

landakram commented 3 years ago

@mdcfe, thanks so much for this PR. Can you see if my additional commits work for your use-case? It's a bit of a hack, but it maintains backward compatibility with the named export.

The downside is that this probably affects treeshaking, but since there will really only be one import, this seems fine. Don't know enough about this though.

mdcfe commented 3 years ago

On my end, nuxt-content is still able to resolve and import remark-wiki-link after adding the back the named export, so all good here. I'm not too knowledgable about treeshaking myself, but I'm not sure this would introduce any new issues given it's a single file module.

landakram commented 3 years ago

Great! Published in 1.0.4. Thanks again for the contribution!