npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

closure-modules

v0.4.3

Published

Easy way to separate your closure library style code into compiled asset files that can be loaded individually.

Downloads

15

Readme

This library should make breaking down your compiled closure-library style code into modules easier.

How to

Stick your module configuration in your package.json under a "closure-modules" key, like so

package.json (real world example)

...
"closure-modules": {
  // All the locations of your JavaScript code and libraries, make sure all these paths are relative
  "js-sources": [
    "node_modules/@alastair/closure-library/closure/goog" 
    , "node_modules/@alastair/closure-library/third_party/closure/goog/dojo/dom" 
    , "node_modules/@alastair/pbx-core/pbx" 
    , "node_modules/@alastair/pb"
    , "node_modules/@alastair/perseus"
    , "node_modules/@alastair/orion"
    , "node_modules/@alastair/titan"
    , "third_party/closure-templates" 
  ],
  // Configure your modules, name them as the key and put the script filepath as the value
  "modules": {
    "claimsProduct": "closureModules/raw/claimsProduct/claims-product.js",
    "testPage": "closureModules/raw/test-page.js"
  },
  // Any externs
  "externs": ["closureModules/raw/claimsProduct/claims-product-externs.js"],
  // Optional, you probably don't need this, but it just prepends this to url paths, and sourcemap paths
  "virtual-dir": "/claims/",
  // Output directory, if omitted defaults to assets
  "output-dir": 'assets'
  // Optional, defaults to true. If your module code is doing weird things, e.g. variables appear to be being overridden or are not what's expected then set this to false.
  "use-types-for-optimization": false
}
...

The module adds a new command generate-closure-modules that can be run via npm scripts

... 
{
  "scripts": [
    "generate": "generate-closure-modules",
    // If you need to debug your compiled code you'll be glad this exists
    "generate-with-sourcemaps": "generate-closure-modules --sourcemaps"
  ]
}
...

Generating the sourcemaps will mean your router will have to play nice serving up any of your JavaScript libraries but the sourcemaps will let you know where any errors are occuring in the compiled code

Loading modules

In your entry point scripts make sure you add goog.require('loadModules') to the top of at least two of your scripts. This is to ensure the loadModules function gets added to the common.js script. In future this will be automated somehow but for now you must add it manually.

Include common.js (this is the shared code that gets generated)

<script type="text/JavaScript" src="assets/common.js"></script>

A lightweight function loadModule gets included in the common code. Somewhere on your webpage you can then load the modules via the names you've given them whenever they are required.

<script type="text/JavaScript">
  loadModule('claimsProduct', function(){
    // Callback fired when script has been loaded
    claimsProduct.init()
  })
</script>