-
-
Save Sar777/189397af2a0a6373dbadeb79452a78c9 to your computer and use it in GitHub Desktop.
Webpack config for an Express app in Node.js
This file contains 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") | |
const fs = require("fs") | |
// -- Webpack configuration -- | |
const config = {} | |
// Application entry point | |
config.entry = "./src/server/index.js" | |
// We build for node | |
config.target = "node" | |
// Node module dependencies should not be bundled | |
config.externals = fs.readdirSync("node_modules") | |
.reduce(function(acc, mod) { | |
if (mod === ".bin") { | |
return acc | |
} | |
acc[mod] = "commonjs " + mod | |
return acc | |
}, {}) | |
// We are outputting a real node app! | |
config.node = { | |
console: false, | |
global: false, | |
process: false, | |
Buffer: false, | |
__filename: false, | |
__dirname: false, | |
} | |
// Output files in the build/ folder | |
config.output = { | |
path: path.join(__dirname, "build"), | |
filename: "[name].js", | |
} | |
config.resolve = { | |
extensions: [ | |
"", | |
".js", | |
".json", | |
], | |
} | |
config.module = {} | |
config.module.loaders = [ | |
// Use babel and eslint to build and validate JavaScript | |
{ | |
test: /\.js$/, | |
exclude: /node_modules/, | |
loaders: [ | |
"babel?{stage:0,jsxPragma:'this.createElement'}", | |
"eslint", | |
], | |
}, | |
// Allow loading of JSON files | |
{ | |
test: /\.json$/, | |
loader: "json", | |
}, | |
] | |
module.exports = config |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment