Skip to content

Instantly share code, notes, and snippets.

@liondancer
Created August 13, 2017 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liondancer/a781c638d8cc77491719e2ed4dbd122f to your computer and use it in GitHub Desktop.
Save liondancer/a781c638d8cc77491719e2ed4dbd122f to your computer and use it in GitHub Desktop.
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Jifts</title>
</head>
<body>
<div id="app"></div>
<script src="./dist/bundle.js"></script>
</body>
</html>
import express from 'express';
import webpack from 'webpack';
import webpackDevMiddleware from 'webpack-dev-middleware';
import path from 'path';
import config from '../../webpack.config.dev';
import open from 'open';
/* eslint-disable no-console */
const port = 3000;
const app = express();
const compiler = webpack(config);
// Tell express to use the webpack-dev-middleware and use the webpack.config.dev.js
// configuration file as a base.
app.use(webpackDevMiddleware(compiler, {
publicPath: config.output.publicPath,
historyApiFallback: true
}));
app.use(require('webpack-hot-middleware')(compiler));
app.get('*', function(req, res) {
res.sendFile(path.join( __dirname, '../index.html'));
});
app.listen(port, err => {
if (err) {
console.log(err);
} else {
open(`http://localhost:${port}`);
}
});
import webpack from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import CleanWebpackPlugin from 'clean-webpack-plugin';
export default {
entry: [
'./app/index'
],
devtool: 'inline-source-map',
target: 'web',
output: {
path: __dirname + '/app/dist/', // Note: Physical files are only output by the production build task `npm run build`.
publicPath: '/',
filename: 'bundle.js'
},
devServer: {
contentBase: './app',
historyApiFallback: {
index: './app/index.html'
}
},
plugins: [
new CleanWebpackPlugin(['dist']),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin()
],
module: {
rules: [
{test: /\.js$/, use: {loader: 'babel-loader'}},
{test: /(\.css)$/, use: ['style-loader', 'css-loader']},
{test: /\.(png|svg|jpg|gif)$/, use: ['file-loader']},
// for fonts
{test: /\.(woff|woff2|eot|ttf|otf)$/, use: ['file-loader']}
]
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment