1.0.0 • Published 9 years ago

save-json-to-window v1.0.0

Weekly downloads
2
License
ISC
Repository
-
Last release
9 years ago

Save JSON to window

Intro

Sometimes its useful to make values created at build-time, available to the frontend.

Usage

To install:

$ npm i save-json-to-window --save-dev

Usage

At the start of your Gulpfile.js you could add:

var package = require('../package.json'),
    saveJsonToWindow = require('../src/index.js'),
    obj = {version: package.version}

saveJsonToWindow('./test/build-values.js', 'buildValues', obj);

Will create a file called build-values.js containing:

window.buildValues = {"version":"1.0.0"}

You can now include build-values.js as a file dependency.

Note: this does a synchronous write of the file.

Caution: it is generally considered bad practice to add anything to window object, proceed with caution..