Skip to content

Instantly share code, notes, and snippets.

@josecaos
Created August 14, 2020 01:12
Show Gist options
  • Select an option

  • Save josecaos/cc7a7da96ebfd87d260d899d8ce618fb to your computer and use it in GitHub Desktop.

Select an option

Save josecaos/cc7a7da96ebfd87d260d899d8ce618fb to your computer and use it in GitHub Desktop.
webpack CCD
const webpack = require('webpack');
const path = require('path');
const config = require('sapper/config/webpack.js');
const pkg = require('./package.json');
const mode = process.env.NODE_ENV;
const dev = mode === 'development';
const alias = { svelte: path.resolve('node_modules', 'svelte') };
const extensions = ['.mjs', '.js', '.json', '.svelte', '.html'];
const mainFields = ['svelte', 'module', 'browser', 'main'];
module.exports = {
client: {
entry: config.client.entry(),
output: config.client.output(),
resolve: { alias, extensions, mainFields },
module: {
rules: [{
test: /\.(png|jpg|gif|mov|ogv|mp4|avi|webm)$/,
loader: 'file-loader',
options: {
esModule: false
}
},
{
test: /\.svg$/i,
use: [{
loader: 'svg-inline-loader',
options: {
removeSVGTagAttrs: false
},
}, ],
},
{
test: /\.(svelte|html)$/,
use: {
loader: 'svelte-loader',
options: {
dev,
hydratable: true,
hotReload: false // pending https://github.com/sveltejs/svelte/issues/2377
}
}
}
]
},
mode,
plugins: [
// pending https://github.com/sveltejs/svelte/issues/2377
// dev && new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
'process.browser': true,
'process.env.NODE_ENV': JSON.stringify(mode),
'process.env.API_URL': JSON.stringify(process.env.API_URL),
'process.env.FRONTEND_URL': JSON.stringify(process.env.FRONTEND_URL),
'process.env.MEDIA_URL': JSON.stringify(process.env.MEDIA_URL),
'process.env.MANTENIMIENTO': JSON.stringify(process.env.MANTENIMIENTO),
'process.env.NO_EXPORTAR': JSON.stringify(process.env.NO_EXPORTAR)
}),
].filter(Boolean),
devtool: dev && 'inline-source-map'
},
server: {
entry: config.server.entry(),
output: config.server.output(),
target: 'node',
resolve: { alias, extensions, mainFields },
externals: Object.keys(pkg.dependencies).concat('encoding'),
module: {
rules: [{
test: /\.(png|jpg|gif|mov|ogv|mp4|avi|webm)$/,
loader: 'file-loader',
options: {
esModule: false
}
},
{
test: /\.svg$/i,
use: [{
loader: 'svg-inline-loader',
options: {
removeSVGTagAttrs: false
},
}, ],
},
{
test: /\.(svelte|html)$/,
use: {
loader: 'svelte-loader',
options: {
css: false,
generate: 'ssr',
dev
}
}
}
]
},
mode: process.env.NODE_ENV,
performance: {
hints: false // it doesn't matter if server.js is large
}
},
serviceworker: {
entry: config.serviceworker.entry(),
output: config.serviceworker.output(),
mode: process.env.NODE_ENV
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment