0.0.2 • Published 3 years ago
transform-json-webpack-plugin v0.0.2
transform-json-webpack-plugin
Webpack plugin to generate a JSON asset file.
Install
npm install --save-dev transform-json-webpack-plugin
Options
Name | Type | Description |
---|---|---|
filename | {String} | Output file name(may include path) |
object | {Object} | Object to add to output file or the properties you wish to modify |
source | {String} | Path to an existing JSON file to extend (optional) |
Usage
In your webpack.config.js
instantiate the plugin.
const TransformJson = require('transform-json-webpack-plugin');
module.exports = {
// webpack configuration
// ...
plugins: [
new TransformJson({
// json configuration
})
]
};
Here is a basic example that creates a mainfest.json
file in your output directory:
webpack.config.js
module.exports = {
output: {
path: 'build/'
},
// ...
plugins: [
new TransformJson({
filename: 'manifest.json',
value: {
gundam: 'wing-zero'
}
})
]
};
That will generate a file that looks like this:
manifest.json
{
"gundam": "wing-zero"
}
Here is a basic example that creates a production deployment version of your package.json
file in your output directory:
webpack.config.js
module.exports = {
output: {
path: 'build/'
},
// ...
plugins: [
new TransformJson({
filename: 'package.json',
source: __dirname + "/package.json",
object: {
devDependencies: {},
scripts: {"start": "node index.js"}
}
})
]
};
That will generate a file that looks like this:
package.json
{
"name": "your-project",
"version": "0.0.1",
"dependencies": { "express": "^4.16.3" },
"devDependencies": {},
"scripts": {"start": "node index.js"}
}