express-webpack-assets
v0.1.0
Published
Middleware for Express.js to load webpack assets
Downloads
3,826
Readme
express-webpack-asset
Middleware to load hashed webpack assets, in combination with https://github.com/kossnocorp/assets-webpack-plugin
Configuration
Example webpack config:
var SaveHashes = require('assets-webpack-plugin');
plugins: [
new SaveHashes({path: path.join(__dirname, 'config')})
],
entry: './main.js',
output: {
path: path.join(__dirname, '.tmp', 'public', 'app'),
filename: "bundle-[name]-[hash].js",
publicPath: "/app/"
},
Express config:
var webpackAssets = require('express-webpack-assets');
app.use(webpackAssets('./config/webpack-assets.json', {
devMode: true/false
}));
Express-webpack-asset can also support you with multiple json files. For that case you need to pass a path of your assets json files, example of usage:
var webpackAssets = require('express-webpack-assets');
app.use(webpackAssets('./config', {
devMode: true/false
}));
Please bear in mind that result of extend will override the object properties with equal names w.r.t. order returned by Nodejs.fs.readDir.
Options
{
devMode: boolean // Enables development mode which disables caching of the manifest, which is useful when the manifest changes rapidly
}
Usage
Example webpack-assets.json (taken from the README in the assets-webpack-plugin project):
{
"one": {
"js": "/js/one_2bb80372ebe8047a68d4.bundle.js"
},
"two": {
"js": "/js/two_2bb80372ebe8047a68d4.bundle.js"
}
}
Two ways of linking in assets. Examples shown linking 'one' asset using express EJS view snippets.
<script src="<%= webpack_asset('one', 'js') %>"></script>
<script src="<%= webpack_asset('one').js %>"></script>