Run shell commands before and after webpack builds [a fork of webpack-silentshell-plugin]
npm install webpack-shell-runner
![npm]()
npm install --save-dev webpack-shell-runner
webpack.config.js:
js
const WebpackSilentShellPlugin = require('webpack-silentshell-plugin');
module.exports = {
...
...
plugins: [
new WebpackSilentShellPlugin({onBuildStart:['echo "Webpack Start"'], onBuildEnd:['echo "Webpack End"']})
],
...
}
`
Example
Insert into your webpack.config.js:
`js
const WebpackSilentShellPlugin = require('webpack-silentshell-plugin');
const path = require('path');
var plugins = [];
plugins.push(new WebpackSilentShellPlugin({
onBuildStart: ['echo "Starting"'],
onBuildEnd: ['python script.py && node script.js']
}));
var config = {
entry: {
app: path.resolve(__dirname, 'src/app.js')
},
output: {
path: path.resolve(__dirname, 'dist'), // regular webpack
filename: 'bundle.js'
},
devServer: {
contentBase: path.resolve(__dirname, 'src') // dev server
},
plugins: plugins,
module: {
loaders: [
{test: /\.js$/, loaders: 'babel'},
{test: /\.scss$/, loader: 'style!css!scss?'},
{test: /\.html$/, loader: 'html-loader'}
]
}
}
module.exports = config;
`
Once the build finishes, a child process is spawned firing both a python and node script.
$3
* onBuildStart: array of scripts to execute on the initial build. Default: [ ]
* onBuildEnd: array of scripts to execute after files are emitted at the end of the compilation. Default: [ ]
onBuildExit: array of scripts to execute after webpack's process is complete. Note: this event also fires in webpack --watch when webpack has finished updating the bundle.* Default: [ ]
* dev: switch for development environments. This causes scripts to execute once. Useful for running HMR on webpack-dev-server or webpack watch mode. Default: true
* safe: switches script execution process from spawn to exec. If running into problems with spawn, turn this setting on. Default: false
* verbose: enable for verbose output. Default: false
$3
If opening a pull request, create an issue describing a fix or feature. Have your pull request point to the issue by writing your commits with the issue number in the message.
Make sure you lint your code by running npm run lint and you can build the library by running npm run build`.