Skip to content

Instantly share code, notes, and snippets.

@astrotim
Created July 25, 2017 04:16
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 astrotim/d701c82f5f477758d4ac85d372df1bfb to your computer and use it in GitHub Desktop.
Save astrotim/d701c82f5f477758d4ac85d372df1bfb to your computer and use it in GitHub Desktop.
Builds site as client side app and runs with Webpack dev server
const path = require('path');
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports = {
entry: {
bundle: path.resolve(__dirname, 'src', 'client.js'),
scripts: path.resolve(__dirname, 'src', 'scripts.js')
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
libraryTarget: 'umd'
},
plugins: [
new CopyWebpackPlugin([
{
from: path.resolve(__dirname, 'src', 'index.html'),
to: path.resolve(__dirname, 'dist')
},
{
from: path.resolve(__dirname, 'fonts'),
to: path.resolve(__dirname, 'dist')
}
])
],
devServer: {
contentBase: path.resolve(__dirname, 'dist'),
port: 3000,
historyApiFallback: true
},
module: {
rules: [
{
test: /\.js$/,
include: [path.resolve(__dirname, 'src')],
use: {
loader: 'babel-loader',
options: {
presets: ['react', 'es2015']
}
}
},
{
test: /\.(css|scss)$/,
use: [
{
loader: 'style-loader'
},
{
loader: 'css-loader',
options: {
modules: true,
camelCase: true,
localIdentName: '[name]__[local]--[hash:base64:5]'
}
},
{
loader: 'postcss-loader',
options: {
plugins: [require('autoprefixer')]
}
},
{
loader: 'sass-loader'
}
]
},
{
test: /\.(woff|woff2)$/,
use: {
loader: 'file-loader?name=fonts/[name].[ext]'
}
}
]
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment