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

Expose Client-side Library #54

Open
dgp1130 opened this issue Dec 8, 2016 · 1 comment
Open

Expose Client-side Library #54

dgp1130 opened this issue Dec 8, 2016 · 1 comment

Comments

@dgp1130
Copy link
Member

dgp1130 commented Dec 8, 2016

Our project builds the uniform.js client-side library directly to the build/ directory which is served to the user. However, most projects will use us by performing an npm install uniform-validation, meaning that build/ directory is hidden inside our node_modules folder and cannot be easily served to the user (it is actually ignored by NPM anyways).

We need a way for the developer to easily serve the client-side library to the user. Something along the lines of a function validator.getClientLib() which would return the client library (as a promise since it needs to be read off the file system). This can then be served to the user when they request whatever URL the developer chooses to host Uniform at (in this case /uniform.js).

app.get("/uniform.js", function (req, res) {
    validator.getClientLib().then(function (lib) {
        res.end(lib);
    }, function (err) {
        res.status(500).end(err);
    });
});

From the client's point of view, they would load the library with simply:

<script src="/uniform.js"></script>

This does make it slightly more complicated to install Uniform and get it working, which is a bit of a drawback. On the plus side, it serves the client and server side libraries off the same codebase installed with the same package manager, so there's no possibility of a version mismatch. The only other options would be something like using bower to manage the client-side package, but that complicates the build process significantly and makes things tricky for the user regardless, since they would have to install the client-side library separately and could easily update one, but forget the other. I think this solution of a simple getClientLib() function is the best option.

@dgp1130 dgp1130 added this to the v0.2.0 milestone Dec 8, 2016
@dgp1130 dgp1130 self-assigned this Dec 8, 2016
dgp1130 added a commit that referenced this issue Dec 8, 2016
@dgp1130
Copy link
Member Author

dgp1130 commented Dec 8, 2016

Implemented the above interface. Works without any known issues.

Went through a few version of the NPM package to figure out how to get .npmignore working correctly. I relearned out how to locally debug packages half-way through this, which reminded me make some documentation for that (#57).

@dgp1130 dgp1130 assigned sawyernovak and unassigned dgp1130 Dec 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants