Skip to content

Instantly share code, notes, and snippets.

@siakaramalegos
Created February 2, 2018 15:35
Show Gist options
  • Save siakaramalegos/35954997658e85cfd444a7207348e951 to your computer and use it in GitHub Desktop.
Save siakaramalegos/35954997658e85cfd444a7207348e951 to your computer and use it in GitHub Desktop.
An incomplete snippet of my static app Webpack configuration
const nodeModulesPath = path.resolve(__dirname, 'node_modules');
const faviconsPath = path.resolve(__dirname, 'app/favicons/');
// ...
const commonConfig = merge([{
context: path.resolve(__dirname, 'app'),
entry: {
index: './javascripts/index.js',
base: './javascripts/base.js',
},
output: {
path: path.resolve(__dirname, 'build'),
filename: '[name].bundle.js',
publicPath: config.publicPath,
},
module: {
rules: [
// Favicons - just pass through to root using same file name
{
include: [faviconsPath],
use: [
{
loader: 'file-loader',
options: { name: '[name].[ext]' }
},
],
},
// Images other than favicons - inline if less than 8K, load files, optimize them
{
test: /\.(png|svg|jpg|gif)$/,
exclude: [nodeModulesPath, faviconsPath],
use: [
{
loader: 'url-loader', // default fallback is file-loader
options: { limit: 8000, name: 'images/[name].[hash].[ext]', }
},
{
loader: 'image-webpack-loader',
options: {
bypassOnDebug: true,
optipng: { optimizationLevel: 3 },
pngquant: { enabled: false },
}
},
],
},
{
test: /\.html$/,
exclude: [nodeModulesPath],
use: [
{ loader: 'file-loader', options: { name: '[name].[ext]' } },
'extract-loader',
{ loader: 'html-loader', options: { minimize: true } },
]
},
// ...
]
},
}])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment