gr2m / moment-parseformat

A moment.js plugin to extract the format of a date/time string
http://gr2m.github.io/moment-parseformat
Apache License 2.0
45 stars 30 forks source link

Doesn't work in the browser when not using require js #54

Closed NoMaillard closed 8 years ago

NoMaillard commented 8 years ago

@gr2m thanks for this great tool ! however, it does not work in the browser... 😢 i did `bower install moment-parse-format --save' and the console would show require is not defined.

Simple way to fix it is to put the whole thing in an iife

gr2m commented 8 years ago

can you use npm to install instead of bower?

After installing with npm, you can add the built file from node_modules/moment-parseformat/dist/moment-parseformat.js.

Or if you want to install it via bower, try bower install https://npmcdn.com/moment-parseformat/dist/moment-parseformat.js

NoMaillard commented 8 years ago

Unfortunately, i can't use npm, we use gulp-wiredep and it can not see that the bower version is installed, and yes i have run bower with --save

Error: Error: moment-parseformat is not installed. Try running `bower install`.
gr2m commented 8 years ago

I’m sorry I don’t know how to work around that, I don’t know much about bower, do you have an idea? Can we somehow point bower install moment-parseformat to install from bower install https://npmcdn.com/moment-parseformat/dist/moment-parseformat.js?

NoMaillard commented 8 years ago

you have to run npm buildwhen you update the package, and then add a bower.json that points to dist/moment-parseformat.js

gr2m commented 8 years ago

Is it enough to have the bower.json and dist/moment-parseformat.js on npm only though? I do not want to commit the dist folder on github

NoMaillard commented 8 years ago

i don't know, but if you look at other packages (momentjs included) they all commit the dist to github. you can easily automate it with gulp

gr2m commented 8 years ago

yes, I know, they do it only because of bower, but it comes with overhead that I cannot add in order to be able to maintain this package, I’m sincerely sorry

NoMaillard commented 8 years ago

alright, thanks anyways...

gr2m commented 8 years ago

in your bower.json, can you set a url instead of a version? Something like this

{
  "name": "test",
  "dependencies": {
    "moment-parseformat": "https://npmcdn.com/moment-parseformat/dist/moment-parseformat.js"
  }
}

You can also set a specific version like this "https://npmcdn.com/moment-parseformat@2.1.3/dist/moment-parseformat.js"

NoMaillard commented 8 years ago

no i get :

moment-parseformat is not installed. Try running `bower install`.
gr2m commented 8 years ago

so this works for me with bower 1.5.2

  1. create a bower.json with the content from by comment above
  2. run bower install
  3. copy the content of bower_components/moment-parseformat/index.js and paste it directly into the console on momentjs.com. moment.parseFormat is working
NoMaillard commented 8 years ago

yes, but i have a gulp script running that injects automatically in the index.html, and that doesn't work, i think i found a workaround though

NoMaillard commented 8 years ago

@gr2m my workaround didn't work, how about i submit a pull request that allows bower install? only thing you have to do more is npm run buildand bump the versions

gr2m commented 8 years ago

the versions get bumped automatically with semantic-release. But as I said before, I will not commit built files to GitHub. But you can do it on a fork?

NoMaillard commented 8 years ago

ah i see. well i would have tried, i'll work off a fork then