Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib/index.js in ES5 #5

Closed
fvicente opened this issue Feb 16, 2017 · 3 comments
Closed

lib/index.js in ES5 #5

fvicente opened this issue Feb 16, 2017 · 3 comments

Comments

@fvicente
Copy link

Hi! thanks for this useful library.
I'm using it in my project, but unfortunately, I cannot use it directly from the node_modules, instead I had to copy the source to my project tree (nothing too bad, your library is tiny after all!). The reason for that is that I'm using webpack which uses uglifyjs for 'production' builds, and uglifyjs doesn't recognises ES6, only ES5. I get the following error:

ERROR in bundle.js from UglifyJs
SyntaxError: Unexpected token: name (numAsString) [./~/date-format/lib/index.js:4,0]

I use ES6 like you, but the difference is that my code gets translated to ES5 with babel before the uglify.

Some people on the Internet suggests that you can develop your libraries in ES6 and release it in ES5 using babel, then you will allow a wider audience for date-format.
Your library's source tree would look like this.

+-- lib
|   +-- library.js (es5)
|   +-- library.min.js (es5)
+-- src
    +-- index.js (es6)
    +-- helpers.js (es6)

What do you think about this? are you interested at all in adding this support for ES5 or just 'not your problem'? 😄

@nomiddlename
Copy link
Owner

I'm on holiday at the moment, so I won't get to check this out properly for a week or two. But my first thought is that there isn't much code in the library, so changing it to be ES5 compatible would probably be easier than adding babel and stuff.

@alizhdanov
Copy link

Hey, have the same issue.
I've temporary fixed it in webpack.config.js by this code:

{
  test: /\.js$/,
  loader: 'babel-loader',
  exclude:  /node_modules\/(?!(date-format)\/).*/, 
  query: {
    presets: ['es2015']
  }
},

Where, in exclude we're excluding everything from node_modules, except date-format. More information here.

Although, I believe you can do the same in .babelrc, if you're using babel with something else, than webpack.

@nomiddlename
Copy link
Owner

I've reverted the code to use ES5 - it should behave nicely for you now. Published to npm in version 1.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants