Last active
December 26, 2018 03:30
-
-
Save maxmilton/80cf8330b29876c1241d4ed345412f27 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What's the contents of
'./utils.js'
?