Skip to content

Instantly share code, notes, and snippets.

@mnutt
Created January 6, 2021 00:55
Show Gist options
  • Save mnutt/f42df095ce09da75ba1c1eced25701e1 to your computer and use it in GitHub Desktop.
Save mnutt/f42df095ce09da75ba1c1eced25701e1 to your computer and use it in GitHub Desktop.
const path = require('path');
const webpack = require('webpack');
module.exports = {
entry: './app.js',
output: {
filename: 'app.js',
sourceMapFilename: 'app.js.map',
path: path.resolve(__dirname, 'output')
},
node: {
// we're running node, so don't want webpack to polyfill any of these
global: false,
// note that if you previously used __filename in ./app.js, when you run after bundling it'll be output/app.js
__filename: false,
__dirname: false
},
target: 'node',
// external standalone source maps
devtool: 'cheap-module-source-map',
// these packages all had trouble with tree-shaking and dynamic imports. leave their require()s alone.
externals: [
{
'node-ssh': 'commonjs node-ssh',
'spawn-sync': 'commonjs spawn-sync',
sharp: 'commonjs sharp'
//formidable: 'commonjs formidable'
}
],
optimization: {
// didn't need smaller, just fewer files; minimization makes debugging a little harder
minimize: false
},
// formidable gives issues unless this thing it uses in its tests is disabled
plugins: [new webpack.DefinePlugin({ 'global.GENTLY': false })],
module: {
wrappedContextRegExp: /$^/,
wrappedContextCritical: false,
// if a module reads all filenames in a directory, then filters to js, then requires those js files,
// webpack will just go ahead and try to require _every_ file even if it doesn't have a js extension
noParse: /\.(ico|png)/,
// sharp loads a native addon; handle it properly
rules: [
{
test: /\.node$/,
loader: 'node-loader'
}
]
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment