andreypopp / autobind-decorator

Decorator to automatically bind methods to class instances
MIT License
1.45k stars 66 forks source link

Can't minify version 2.2.0 #69

Closed kristofferabell closed 5 years ago

kristofferabell commented 5 years ago

When I deploy my project I get:

Failed to minify the code from this file: ./node_modules/autobind-decorator/src/index.js:7

New issue for version 2.2.0.

wangweida commented 5 years ago

same question

welikoiwanenko commented 5 years ago

Same behavior

stevemao commented 5 years ago

Based on very little info I’m given, I guess that your minifier is reading the entry point from the “module” field. If your tool can’t understand let it should still read the “dist“ entry, which is exactly the same file as v2.1

wangweida commented 5 years ago

My solution: import HTML5Backend from 'react-dnd-html5-backend/dist/ReactDnDHTML5Backend'

stevemao commented 5 years ago

@wangweida what if i change my internal folder structure and this would break again.

stevemao commented 5 years ago

Given this little information I don't see there's a problem with this module. What's new in 2.2.0 is we added a module entry for those who like to use the new standard javascript syntax (especially es modules for tree shaking). If your tool can't understand ES6+ just use the original main entry.

kristofferabell commented 5 years ago

Hi @stevemao

I apologize but I don't understand your answer. I am using webpack@3.11 and I don't know how to configure it to use "the original main entry" for this sub-sub-dependency in my application.

Apologies if the question is dump and/ or outside this project.

stevemao commented 5 years ago

see https://webpack.js.org/configuration/resolve/#resolve-mainfields try this:

module.exports = {
  //...
  resolve: {
    mainFields: ['main']
  }
};

But I think your babel should transpile your node_modules. I always check create-react-app as a reference.

andreymal commented 5 years ago

@stevemao can you mention this Webpack configuration in README? As you can see, this is a common issue (I also ran into this just now)

But I think your babel should transpile your node_modules.

I think not :)

stevemao commented 5 years ago

@andreymal For those who want to use modern javascript and only target modern browsers/env what's your recommendation?

stevemao commented 5 years ago

The thing is, different users have their different target environment. With a transpiler, you can just compile the code to whatever target you want.

andreymal commented 5 years ago

@stevemao I don't want to make any recommendations (actually I'm not a professional js developer), but I don't want to use a transpiler for node_modules, because it's too slow for me

But thanks for README 👍

stevemao commented 5 years ago

You don’t have to transpile it if your target environment understands it (chrome supports let a few years ago). You don’t have to use webpack, Babel or uglify if you don’t need them :) they slow you down heaps more. It’s probably a good idea to understand how they work and why before using a tool IMO :p

Sent from my iPhone

On 10 Nov 2018, at 10:10 am, andreymal notifications@github.com wrote:

@stevemao I don't want to make any recommendations (actually I'm not a professional js developer), but I don't want to use a transpiler for node_modules, because it's too slow for me

But thanks for README 👍

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

andreymal commented 5 years ago

My target is IE11 :) Autobind can't work in IE without a transpiler.

Anyway, a transpiler is needed for JSX, core-js, stage-0 features and other good (but slow) things. I'm trying to balance between speed and convenience

stevemao commented 5 years ago

The files we published are just standard javascript, not JSX, typescript, and stage-0 :)

TotooriaHyperion commented 5 years ago

actually few library needs babel/typescript transpile: image

I want to use es6 module without transpile all js in node_modules to speed up webpack. All other library works well only this act differently. Can we just transpile the syntax to es5 but preserve the module for es6 module entry? As redux does: image

stevemao commented 5 years ago

Transpiling node_modules should only be minimal as they should all be standard javascript. You could look it up at create-react-app. I use https://github.com/sindresorhus/ky, this package is not for node at all but only for the browsers. Please read https://github.com/sindresorhus/ky/issues/44 and https://babeljs.io/blog/2018/06/26/on-consuming-and-publishing-es2015+-packages

funny thing is es6 module comes later than let so you would think that normally environments support es6 module would have already support let?

Another option is to use https://github.com/SamVerschueren/babel-engine-plugin, even though i think engines field is more for devving not for consuming? But happy to add engines field in package.json.