UNPKG

@bbc/spartacus

Version:
42 lines (38 loc) 1.31 kB
/* eslint-disable import/no-dynamic-require, global-require */ module.exports = ({ resolvePath, START_DEV_SERVER, appDirectory }) => { const nodeExternals = require(`${appDirectory}/node_modules/webpack-node-externals`); const serverConfig = { target: 'node', // compile for server environment entry: START_DEV_SERVER ? ['webpack/hot/poll?100', './src'] : ['./src'], output: { path: resolvePath('build'), filename: 'server.js', }, externals: [ /** * Prevents `node_modules` from being bundled into the server.js * And therefore stops `node_modules` being watched for file changes */ nodeExternals({ whitelist: ['webpack/hot/poll?100'], }), ], watch: true, node: { /** * Override webpacks default handling of __dirname * which replaces it with '/'. */ __dirname: false, }, }; if (START_DEV_SERVER) { const StartServerPlugin = require(`${appDirectory}/node_modules/start-server-webpack-plugin`); const webpack = require(`${appDirectory}/node_modules/webpack`); serverConfig.plugins = [ new webpack.HotModuleReplacementPlugin(), new StartServerPlugin('server.js'), // only start the server if we've run `npm run dev` ]; } return serverConfig; };