kentcdodds / match-sorter

Simple, expected, and deterministic best-match sorting of an array in JavaScript

Home Page:https://npm.im/match-sorter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use without remove-accents

Daniel15 opened this issue ยท comments

Is there a way to use this library without pulling in the remove-accents library? My strings are all in English so I don't need to handle diacritics, and would rather not bloat out the bundle size with stuff I don't need. I'm using Webpack.

Looking at dist/match-sorter.esm.js (https://unpkg.com/match-sorter@3.1.1/dist/match-sorter.esm.js), it seems like it's compiled in and there's no way to replace it. It also seems like the original source code is not packaged in the npm package, so I can't just do something like import matchSorter from 'match-sorter/src/index' and then shim remove-accents via NormalModuleReplacementPlugin.

I would be in favor of changing it to enable this. I'm pretty sure that all it would take is to remove the bundledDependencies config from package.json. Would you like to give that a shot?

Sure, I can try that and see if it works.

Just as a test, what I did was updated my project's package.json to load this library from GitHub (to get the uncompiled code) instead of npm:

"match-sorter": "kentcdodds/match-sorter#v3.1.1",

Then I modified my Webpack config so that import matchSorter from 'match-sorter' loads src/index.js, and shimmed remove-accents to instead load a package that just returned the string unmodified:

    new webpack.NormalModuleReplacementPlugin(
      /match-sorter/,
      __dirname + '/node_modules/match-sorter/src/index.js',
    ),
    new webpack.NormalModuleReplacementPlugin(
      /remove-accents/,
      __dirname + '/public/assets/js/removeAccentsShim.js',
    ),

removeAccentsShim.js:

export default function removeAccentsShim(input) {
  return input;
}

This worked fine!

@kentcdodds - That didn't work for me :(

I modified package.json to remove the bundledDependencies, ran the build, and match-sorter.esm.js still contains the contents of remove-accents, rather than an import statement like I expected. Admittedly I haven't done much JS stuff for a long time, so I might be missing something obvious.

As an aside, npm run build didn't work properly for me on Windows... It opened cross-env.js in Notepad (lolwut). I guess I don't have .js files associated with Node. I just ran the build command manually.

I'm afraid that I won't have time to look into this for a few weeks. But I'll try to give it a look when I get the time.

Alrighty. I've fixed this. You should be able to re-map everything properly now.

๐ŸŽ‰ This issue has been resolved in version 4.0.0 ๐ŸŽ‰

The release is available on:

Your semantic-release bot ๐Ÿ“ฆ๐Ÿš€

Works perfectly! Thank you so much! :D