Moment-timezone: JSON data as Javascript for Bower

Created on 19 Jun 2014  路  11Comments  路  Source: moment/moment-timezone

When bower installing moment-timezone, the data is installed as json files. While for some projects that's fine to get the data asynchronously with AJAX, it's not as useful for projects like ours where we minify/concatenate a front-end application and deploy it. This build process, I imagine, is pretty common as well.

Is there a way to have a separate github repository for the bower package (Angular does it) where the json data is wrapped with

moment.tz.add("zones_in_latest.json");moment.tz.link("links_in_latest.json");

And then include the data file in the main property in your bower.json. This way, projects that are front-end clients can easily install and manage this awesome tool with bower.

Most helpful comment

The bower spec as of 0.5.0 defaults to using "moment-timezone-with-data-2010-2020.js" at present (the value for 'main'). If I want "moment-timezone-with-data.js" instead, what's the best approach to achieving that? Editing .bower after running 'bower install'? (That seems potentially fragile if the module was ever installed and reinstalled.)

Appreciate any guidance.

All 11 comments

The plan is to add some more build targets to the min directory. Probably something like the following. The specific years are TBD still.

min/moment-timezone.min.js
min/moment-timezone-with-data.min.js
min/moment-timezone-with-data-after-1970.min.js
min/moment-timezone-with-data-after-2000.min.js
min/moment-timezone-with-data-after-2010.min.js
min/moment-timezone-with-data-2010-2020.min.js

Out of curiosity, what tool are you using to minify + concat? Does it require the main property in bower.json in order to concat, or can you substitute other paths?

For example, a lot of Angular projects will scaffold their projects with the Yeoman generator for angular. For bower packages, it wires them up to a single html file using grunt-bower-install, and all of the scripts that are included on that html file will be concatenated and then minified with something like grunt-uglify.

grunt-bower-install grabs the bower packages from the main property, so yes, it's kind of expected. Of course, you can add whatever custom paths you want, but it'd be ideal for it to "Just Work."

Though, given how complex timezones get, each project might only want certain data. I'm sure you can remedy this by way documentation on the website and in the console - there you can instruct users to generate the files that the bower packages point to. Something like that, maybe?

I added the task to build files and inject data. Right now, there are only builds for all data or 2010-2020. I think those are sane enough defaults for now, if not, there will be the data builder online as well.

I changed the main bower entry point to use moment-timezone-with-data-2010-2020.js as I think that will probably be the most common use case.

The main attribute can also take an array, in case you wanted to modularize that code a little

This is released in 0.1.0.

@timrwood As of version 0.3.1, when I bower install moment-timezone, there does not exist a moment-timezone-with-data.js in my moment-timezone folder.

_Edit_ Oh, there's a 'builds' folder! Yup. That's where they are...

The bower spec as of 0.5.0 defaults to using "moment-timezone-with-data-2010-2020.js" at present (the value for 'main'). If I want "moment-timezone-with-data.js" instead, what's the best approach to achieving that? Editing .bower after running 'bower install'? (That seems potentially fragile if the module was ever installed and reinstalled.)

Appreciate any guidance.

@stephent fork

@chadfurman seems like a drastic step for what is essentially configuration...

You're changing a dependency. You can fork and send a PR, or you can change the dependency in the cloned down repo w/o a PR and worry about it getting erased.

Edit: Alternatively, change the code locally, commit, and handle any merge conflicts when you go to update. @stephent

Another problem with forking is that it cannot be easily applied to all releases. One would need to update the own fork when willing to update moment-timezone.

Was this page helpful?
0 / 5 - 0 ratings