karolyimusic-webplayer/webpack.config.js

92 lines
2.8 KiB
JavaScript
Raw Permalink Normal View History

import path from 'path'
2022-02-23 22:23:56 +01:00
import HtmlWebpackPlugin from 'html-webpack-plugin'
import { fileURLToPath } from 'url'
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
2022-02-23 22:23:56 +01:00
const isProduction = process.env.NODE_ENV == 'production';
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'
const _myFileName = fileURLToPath(import.meta.url)
const _myDirName = path.dirname(_myFileName)
2022-02-23 22:23:56 +01:00
import webpack from 'webpack'
2022-02-23 22:23:56 +01:00
const config = {
entry: [
'./src/index.ts',
2022-02-25 21:26:12 +01:00
'./src/sass/player.sass',
2022-02-23 22:23:56 +01:00
],
2024-04-20 16:24:23 +02:00
devtool: isProduction ? false : 'inline-source-map',
2022-02-23 22:23:56 +01:00
output: {
path: path.resolve(_myDirName, 'dist'),
2022-02-28 22:37:50 +01:00
filename: isProduction ? '[name]-[chunkhash:6].js' : '[name].js',
2022-02-23 22:23:56 +01:00
},
devServer: {
open: true,
host: 'localhost',
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
fallback: {
// make it shut up about missing nodejs plugins in the browser
util: false,
}
},
plugins: [
new HtmlWebpackPlugin({
template: 'index.html',
}),
2022-02-28 22:37:50 +01:00
// Turn this on only when you need an overview about the bundle contents
// new BundleAnalyzerPlugin(),
new MiniCssExtractPlugin({
filename: isProduction ? 'stylesheets/[name]-[contenthash:6].css' : 'stylesheets/[name].css',
}),
// Use this so it wont load extra chunks deferred, which breaks
// embedding the main.js script into a hugo site, for example
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1,
})
2022-02-23 22:23:56 +01:00
// new NodePolyfillPlugin({
// excludeAliases: ['console'],
// }),
// Add your plugins here
// Learn more about plugins from https://webpack.js.org/configuration/plugins/
],
module: {
rules: [
{
test: /\.(js|jsx)$/i,
loader: 'babel-loader',
},
{
test: /\.(ts|tsx)$/i,
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.s[ac]ss$/i,
2022-02-28 22:37:50 +01:00
use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader', 'sass-loader'],
2022-02-23 22:23:56 +01:00
},
{
test: /\.css$/i,
2024-04-20 16:24:23 +02:00
use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader'],
2022-02-23 22:23:56 +01:00
},
{
test: /\.(eot|svg|ttf|woff|woff2|png|jpg|gif)$/i,
type: 'asset',
},
// Add your rules for custom modules here
// Learn more about loaders from https://webpack.js.org/loaders/
],
},
};
export default () => {
2022-02-23 22:23:56 +01:00
if (isProduction) {
config.mode = 'production';
} else {
config.mode = 'development';
}
return config;
};