2020-07-17 19:29:18 +02:00
|
|
|
const path = require('path')
|
2020-11-15 15:13:49 +01:00
|
|
|
const fs = require('fs')
|
2020-07-17 19:29:18 +02:00
|
|
|
const pkg = require('./package.json')
|
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin')
|
|
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin')
|
2020-12-15 10:23:20 +01:00
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
2020-07-17 19:29:18 +02:00
|
|
|
const { GenerateSW } = require('workbox-webpack-plugin')
|
|
|
|
|
|
|
|
const destination = path.join(__dirname, 'dist')
|
2020-11-15 15:13:49 +01:00
|
|
|
const isFirebaseEnv = process.env.NODE_APP === 'firebase'
|
|
|
|
const firebaseConfigFilePath = path.join(__dirname, '.firebaserc')
|
|
|
|
const hasFirebaseConfig = fs.existsSync(firebaseConfigFilePath)
|
|
|
|
|
|
|
|
if (isFirebaseEnv && hasFirebaseConfig) {
|
|
|
|
console.info('Prepare build for Firebase hosting')
|
|
|
|
}
|
|
|
|
|
2020-07-17 19:29:18 +02:00
|
|
|
module.exports = {
|
2020-07-17 20:18:55 +02:00
|
|
|
entry: path.join(__dirname, 'lib', 'static', 'index.js'),
|
2020-07-17 19:29:18 +02:00
|
|
|
output: {
|
|
|
|
filename: '[name].[hash].js',
|
|
|
|
path: destination,
|
|
|
|
},
|
2020-12-15 10:23:20 +01:00
|
|
|
resolve: {
|
|
|
|
alias: {
|
|
|
|
svelte: path.resolve('node_modules', 'svelte'),
|
|
|
|
},
|
|
|
|
extensions: [ '.mjs', '.js', '.svelte' ],
|
|
|
|
mainFields: [ 'svelte', 'browser', 'module', 'main' ],
|
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.(svelte)$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
|
|
|
loader: 'svelte-loader',
|
|
|
|
options: {
|
|
|
|
emitCss: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
|
|
|
use: [ MiniCssExtractPlugin.loader, 'css-loader' ],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2020-07-17 19:29:18 +02:00
|
|
|
plugins: [
|
|
|
|
new CopyWebpackPlugin({
|
|
|
|
patterns: [
|
|
|
|
{ from: path.join(__dirname, 'lib', 'static', '{*.ico,*.json,*.png,*.css}'), to: destination, flatten: true },
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
template: path.join(__dirname, 'lib', 'static', 'index.html'),
|
|
|
|
version: pkg.version,
|
|
|
|
inject: 'body',
|
|
|
|
}),
|
2020-12-15 10:23:20 +01:00
|
|
|
new MiniCssExtractPlugin(),
|
2020-07-17 19:29:18 +02:00
|
|
|
new GenerateSW({
|
|
|
|
swDest: 'sw.js',
|
|
|
|
clientsClaim: true,
|
|
|
|
skipWaiting: true,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}
|