Skip to content

Instantly share code, notes, and snippets.

@kazuma1989
Last active January 22, 2018 23:11
Show Gist options
  • Save kazuma1989/6b87b33f9c1fc997fbd32f8633ed99d8 to your computer and use it in GitHub Desktop.
Save kazuma1989/6b87b33f9c1fc997fbd32f8633ed99d8 to your computer and use it in GitHub Desktop.
Write HTML with Handlebars and dev-server watching files
{
"name": "raw-hbs",
"version": "1.0.0",
"main": "index.js",
"author": "kazuma1989 <funifuni.1204@gmail.com>",
"license": "MIT",
"scripts": {
"start": "webpack-dev-server",
"build": "cross-env NODE_ENV=production webpack"
},
"devDependencies": {
"cross-env": "^5.1.3",
"handlebars": "^4.0.11",
"handlebars-loader": "^1.6.0",
"html-webpack-plugin": "^2.30.1",
"webpack": "^3.10.0",
"webpack-dev-server": "^2.11.1"
}
}
const HtmlWebpackPlugin = require('html-webpack-plugin');
const pages = [
'index',
'search',
'detail',
];
module.exports = {
entry: __dirname + '/src/main.js',
output: {
path: __dirname + '/dist',
filename: '[name].[chunkhash:8].js'
},
module: {
loaders: [
{
test: /\.hbs$/,
loader: 'handlebars-loader'
}
]
},
devServer: {
open: true,
// Expose the dev server to the internet
host: process.env.HOST || '0.0.0.0',
disableHostCheck: true
},
plugins: pages.map(page =>
new HtmlWebpackPlugin({
filename: page + '.html',
template: __dirname + '/src/' + page + '.hbs',
chunks: []
})
)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment