Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commands not found error after on hooks(onBuildStart and onBuildEnd) #69

Open
bracano45 opened this issue Jan 15, 2019 · 1 comment
Open

Comments

@bracano45
Copy link

This is how my Webpack config files looks like.

`const path = require('path');
const webpack = require('webpack');
const nodeExternals = require('webpack-node-externals');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const NodemonPlugin = require('nodemon-webpack-plugin');
const WebpackShellPlugin = require('webpack-shell-plugin');

const ENV = process.env.NODE_ENV.trim();

const isDev = ENV !== 'production';
const isProd = ENV === 'production';

function setDevTool() {
if (isDev) {
return 'inline-source-map';
} else if (isProd) {
return 'source-map';
} else {
return 'eval-source-map';
}
}

const browserConfig = {
mode: ENV,
entry: './src/client/index.js',
output: {
path: path.resolve(__dirname, 'public'),
filename: 'bundle.js',
publicPath: '/'
},
devtool: setDevTool(),
module: {
rules: [
{
test: /.(js)$/,
use: 'babel-loader'
}
]
},
plugins: [
new webpack.DefinePlugin({
isBrowser: "true"
})
]
}

const serverConfig = {
mode: ENV,
entry: './src/server/index.js',
target: 'node',
externals: [nodeExternals()],
output: {
path: __dirname,
filename: 'server.js',
publicPath: '/'
},
devtool: setDevTool(),
module: {
rules: [
{
test: /.(js)$/,
use: 'babel-loader'
}
]
},
plugins: [
new webpack.DefinePlugin({
isBrowser: "false"
})
]
}

if (isDev) {
serverConfig.plugins.push(
new NodemonPlugin()
);
}

if (isProd) {
browserConfig.plugins.push(
new UglifyJSPlugin({
sourceMap: true
})
);
serverConfig.plugins.push(
new UglifyJSPlugin({
sourceMap: true
}),
new WebpackShellPlugin({
onBuildStart: ['echo "Production Build Start."'],
onBuildEnd: ['node server.js']
})
);
}

module.exports = [browserConfig, serverConfig];
`

When I run 'NODE_ENV=production webpack -w', it returns error after webpack build.
Error: Command failed: node server.js

Please give me an idea why this error occurs if anybody knows why.
Thank you.

@mikeerickson
Copy link

Hard to decipher on phone as code is not properly commented, but it looks like you are not pushing the plugin call onto your desired plugin array. Near end of config, you can push to browser or server plugin (see previous code) but not for the WebpackShellPlugin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants