JS Output to File Webpack Plugin
Lightweight webpack plugin that takes in a JS file and writes its output into a file.
Useful for generating files like manifest.json.
Installation
yarn add --dev js-output-file-webpack-plugin
or
npm i --save-dev js-output-file-webpack-plugin
Usage
In webpack.config.js
:
const JSOutputFilePlugin = ; const config = context: path output: path: path plugins: source: 'manifest.json.js' ; moduleexports = config;
In src/manifest.json.js
:
const pkg = ; module { const manifest = name: 'Example manifest' // use some dynamically generated variables version: pkgversion icons: '16': 'icons/icon16.png' '48': 'icons/icon48.png' '128': 'icons/icon128.png' background: scripts: 'bg.js' persistent: false ; // environment specific rendering if env === 'development' manifest'content_security_policy' = "script-src 'self' 'unsafe-eval'; object-src 'self'"; return manifest;};
JSOutputFilePlugin
will output a file of the same name in output directory, with the .js
extension stripped.
Running the webpack compiler will yield dist/manifest.json
:
// Prettified for example purposes.// Actual JSON output will be minified unless the return value is a string.