Skip to content

Instantly share code, notes, and snippets.

@h1romas4
Last active May 19, 2020 02:43
Show Gist options
  • Save h1romas4/8810b21ed2dab6a98231934a38961b7c to your computer and use it in GitHub Desktop.
Save h1romas4/8810b21ed2dab6a98231934a38961b7c to your computer and use it in GitHub Desktop.
express でつくられたアプリをリリース用にバンドルする webpack(express はバンドルできないようなので除外)
{
"name": "app",
"version": "1.0.0",
"description": "app",
"repository": {},
"license": "",
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.0",
"babel-loader": "^8.1.0",
"webpack": "^4.42.1",
"webpack-cli": "^3.3.11"
},
"dependencies": {
"express": "^4.17.1",
"log4js": "^6.1.2"
},
"scripts": {
"start": "node src/app.js",
"debug": "node --inspect=0.0.0.0 src/app.js",
"build": "webpack",
"server:start": "npm run build && node dist/app-bundle.js",
"server:debug": "node --inspect=0.0.0.0 dist/app-bundle.js"
}
}
const path = require('path');
module.exports = {
devtool: "source-map",
mode: 'production',
target: 'node',
// use express in server install (npm install express on server)
externals: function (context, request, callback) {
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