Created
September 15, 2015 13:55
-
-
Save madx/53853c3d7b527744917f 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 |
Awesome! 👍
Question: the webpack builds one file. What happens to relative urls in the code, for example loading assets or accessing json files?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Which webpack version is compatible with this