<|start_filename|>test/simple/data.json.js<|end_filename|>
// data.json.js

// can use serverside-only dependencies
var fs = require('fs')
var path = require('path')
var readme = fs.readFileSync(path.join(__dirname, '/../../Readme.md'), 'utf8')
readme = readme.split('\n')[0] // (just grab header for demo)

// any other dependencies that are only used in here won't be included in bundle
var tape = require('tape') // some random dependency

// whatever the value of module.exports is will be serialised to JSON
module.exports = {
  readme: readme,
  tape: tape, // tape happens to be a function so it won't serialise.
  random: Math.random() // will be fixed to whatever value is generated at compile-time
}


<|start_filename|>test/index.js<|end_filename|>
var fs = require('fs')
var path = require('path')
var exec = require('child_process').exec
var test = require('tape')

var TEST_DIR = path.join(__dirname, '/simple')
var TEST_FILE = path.join(TEST_DIR, '/build.js')

test('setup', function (t) {
  fs.unlink(TEST_FILE, function (_) {
    t.end()
  })
})

test('tojson-loader ', function (t) {
  exec('webpack --bail', {cwd: TEST_DIR}, function (err, stdout, stderr) {
    t.ifError(err)
    var build = fs.readFileSync(TEST_FILE, 'utf8')
    t.ok(build.indexOf('# tojson-loader') !== -1, 'contains header from readme')
    t.ok(build.indexOf('require(\'tape\')') === -1, 'does not contain dependencies')
    t.end()
  })
})


<|start_filename|>package.json<|end_filename|>
{
  "name": "tojson-loader",
  "version": "1.0.5",
  "description": "Serialize module exports as JSON. Cache generated static data as JSON at build time.",
  "main": "index.js",
  "directories": {
    "test": "test"
  },
  "devDependencies": {
    "node-libs-browser": "^2.0.0",
    "standard": "^10.0.2",
    "tape": "^4.7.0",
    "webpack": "^3.0.0"
  },
  "scripts": {
    "test": "tape test/index.js && npm run lint",
    "lint": "standard"
  },
  "keywords": [
    "webpack",
    "json",
    "loader",
    "serialise",
    "serialize",
    "generated",
    "cache",
    "universal",
    "isomorphic",
    "static"
  ],
  "author": "<NAME> <<EMAIL>>",
  "license": "ISC",
  "dependencies": {},
  "repository": {
    "type": "git",
    "url": "git+https://github.com/timoxley/tojson-loader.git"
  },
  "bugs": {
    "url": "https://github.com/timoxley/tojson-loader/issues"
  },
  "homepage": "https://github.com/timoxley/tojson-loader#readme"
}


<|start_filename|>test/simple/webpack.config.js<|end_filename|>
var path = require('path')

module.exports = {
  entry: './index.js',
  output: {
    path: __dirname,
    filename: 'build.js'
  },

  module: {
    loaders: [
      {
        // Use *.json.js extension to bake exported JS data into JSON
        test: /\.json\.js/,
        loader: path.join(__dirname, '/../../index.js')
      }
    ]
  }
}


<|start_filename|>test/simple/index.js<|end_filename|>
console.log(require('./data.json.js'))
