Skip to content

Instantly share code, notes, and snippets.

@astrotim
Created July 25, 2017 04:17
Show Gist options
  • Save astrotim/41309ae5769862795bcd07588711cf1a to your computer and use it in GitHub Desktop.
Save astrotim/41309ae5769862795bcd07588711cf1a to your computer and use it in GitHub Desktop.
Builds site as static files using StaticSiteGeneratorPlugin
const path = require('path');
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const StaticSiteGeneratorPlugin = require('static-site-generator-webpack-plugin');
module.exports = {
entry: [path.resolve(__dirname, 'src')],
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
libraryTarget: 'umd'
},
plugins: [
new ExtractTextPlugin('style.css'),
new StaticSiteGeneratorPlugin({
crawl: true,
paths: ['/']
}),
new CopyWebpackPlugin([
{
from: path.resolve(__dirname, 'src', 'favicon.ico'),
to: path.resolve(__dirname, 'dist')
}
])
],
module: {
rules: [
{
test: /\.js$/,
include: [path.resolve(__dirname, 'src')],
use: {
loader: 'babel-loader',
options: {
presets: ['react', 'es2015']
}
}
},
{
test: /\.(css|scss)$/,
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
modules: true,
camelCase: true,
localIdentName: '[name]__[local]--[hash:base64:5]'
}
},
{
loader: 'postcss-loader',
options: {
plugins: [require('autoprefixer')]
}
},
{
loader: 'sass-loader'
}
]
})
}
]
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment