Skip to content

Instantly share code, notes, and snippets.

@maxmilton
Last active December 26, 2018 03:30
Show Gist options
  • Save maxmilton/80cf8330b29876c1241d4ed345412f27 to your computer and use it in GitHub Desktop.
Save maxmilton/80cf8330b29876c1241d4ed345412f27 to your computer and use it in GitHub Desktop.
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const config = require('sapper/webpack/config.js');
const { svelteMinifyHtml, sveltePostcss } = require('./utils.js');
const mode = process.env.NODE_ENV;
const isDev = mode === 'development';
module.exports = {
entry: config.client.entry(),
output: config.client.output(),
resolve: {
extensions: ['.js', '.json', '.html'],
},
module: {
rules: [
{
test: /\.html$/,
exclude: /node_modules/,
use: {
loader: 'svelte-loader',
options: {
preprocess: {
// only remove whitespace in production; better feedback during development
...(isDev ? {} : { markup: svelteMinifyHtml({ safe: false }) }),
style: sveltePostcss(),
},
emitCss: true, // pass CSS to webpack
hydratable: true,
hotReload: isDev,
dev: isDev,
},
},
},
{
test: /\.css$/,
use: [
isDev
? { loader: 'style-loader', options: { sourceMap: true }} // CSS HMR
: MiniCssExtractPlugin.loader, // extract CSS in production builds
{ loader: 'css-loader', options: { sourceMap: isDev }},
{ loader: 'postcss-loader', options: { sourceMap: isDev }},
],
},
],
},
mode,
plugins: [
isDev && new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
'process.browser': true,
'process.env.NODE_ENV': JSON.stringify(mode),
}),
new MiniCssExtractPlugin({
filename: '[hash]/[name].css',
chunkFilename: '[hash]/[name].[id].css',
}),
].filter(Boolean),
...(isDev ? {} : { optimization: {
// combine all CSS into a single file
splitChunks: {
cacheGroups: {
styles: {
name: 'main',
test: /\.css$/,
chunks: 'all',
enforce: true,
},
},
},
}}),
devtool: isDev && 'eval-source-map',
};
@orenrobi
Copy link

What's the contents of './utils.js'?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment