Last active
April 7, 2020 07:37
-
-
Save h1romas4/79fd7ed390ff65a8873c2c8e51c44e1d to your computer and use it in GitHub Desktop.
express だけ除外してバンドルする node 向け webpack.config.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
module.exports = { | |
devtool: "source-map", | |
mode: 'production', | |
target: 'node', | |
externals: function (context, request, callback) { | |
// use express in server install | |
// npm install express | |
// NODE_PATH=`npm root -g` node dist/app-bundle.js | |
if (request === 'express') { | |
return callback(null, 'commonjs ' + request); | |
} | |
callback(); | |
}, | |
entry: { | |
app: './src/app.js', | |
}, | |
output: { | |
filename: 'app-bundle.js', | |
path: path.join(__dirname, '/dist'), // eslint-disable-line | |
}, | |
optimization: { | |
minimize: false | |
}, | |
plugins: [ | |
], | |
module: { | |
rules: [ | |
{ | |
test: /\.js$/, | |
exclude: /node_modules/, | |
use: [{ | |
loader: 'babel-loader', | |
options: { | |
presets: [[ | |
'@babel/preset-env', { | |
"targets": { | |
"node": "current" | |
} | |
} | |
]] | |
} | |
}] | |
} | |
] | |
}, | |
resolve: { | |
extensions: ['.js'], | |
modules: [ | |
"node_modules" | |
] | |
}, | |
performance: { | |
hints: false | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment