sindresorhus/sort-on

Provide ES5 version for browser environment

sqal opened this issue · 12 comments

sqal commented

Hi @sindresorhus. Can you please provide ES5 version so it can work in older browsers that doesn't support arrow functions and other goodies. I use webpack and babel-loader in my project but I don't transpile any modules from node_modules directory:

  test: /\.js$/,
  exclude: /node_modules/,
  loader: 'babel-loader',
}

So.. it would be to at least have a choice between ES5 and ES6 version. Thanks :)

We aim for Node.js, not the browser. You can find a more detailed explanation here sindresorhus/ama#446

I encourage you to open an issue on https://github.com/webpack/webpack/issues about including support for automatic transpiling of node_modules that need it.

You don't need to open an issue there. Just don't exclude modules like this for babel-loader.

sqal commented

Thanks for explanation and help guys. I decided to just add this module to the paths transformed by the babel-loader

include: [
  paths.appSrc,
  path.join(paths.appNodeModules, 'sort-on'),
]

@stevemao Yes, they do. I'm tired of getting issues like this on all my repos. It's better if Webpack resolved this.

@sindresorhus Jup, that's why I have it as a saved reply ;)

screen shot 2017-03-24 at 13 40 52

@sindresorhus I don't see how this fit in webpack either.
@sqal I have made a module for you: https://github.com/stevemao/sindre-module-paths
You can do this:

const path = require('path')
const sindreModulePaths = require('sindre-module-paths')

// Then in some async function
const es6ModulePaths = await sindreModulePaths();

{
  test: /\.js$/,
  include: [
    ...es6ModulePaths,
    path.resolve(__dirname, 'src'),
  ],
  use: 'babel-loader',
}

Let me know if you have any questions :)

Can't we just detect if the engines field is set to Node.js 4+? Then we would have a general solution that works if the field is being used correctly. If it's not present, people can always add a PR. Sindre always uses it so that's covered.

Can't we just detect if the engines field is set to Node.js 4+?

Yes, I've suggested that to both the Babel and Webpack maintainers.

@stevemao 🙄

I'm not the only one targeting Node.js 4 these days, fwiw.

This is such a typical front-end attitude. Instead of actually trying to fix the core problem, you independently create different layers of indirections that just works around part of the problem.

@stevemao You know could have actually made a useful module if you checked the "engine" field instead.