This plugin allows you to return from a js file string, that will be saved as a file in the output directory.
Constructor of the plugin takes a function that takes a file name and returns a boolean value. If the function returns true, the js code will be replaced by what this code returns. By default it works for all files that not ends with .js
.
npm install webpack-emit-static-file-plugin
webpack.config.js
export default {
entry: './random.js',
output: {
path: __dirname+'/dist',
filename: 'random.txt'
},
plugins:[new WebpackEmitStaticFilePlugin(name=>name.endsWith('.txt'))]
}
random.js
return Math.floor(Math.random()*1000);