grid/webpack.config.js

81 lines
2.3 KiB
JavaScript
Raw Normal View History

const path = require('path');
2023-01-09 23:13:06 +00:00
const HtmlWebpackPlugin = require('html-webpack-plugin');
2023-01-09 23:38:02 +00:00
function relpath(fp) {
return path.resolve(__dirname, ...fp.split('/'));
}
module.exports = {
2023-01-10 00:01:59 +00:00
// note: production disables the in-memory cache
mode: 'development', // 'production',
2023-01-09 23:13:06 +00:00
entry: {
2023-01-10 00:44:13 +00:00
index: relpath('src/index.tsx'),
2023-01-09 23:13:06 +00:00
},
2023-01-10 00:01:59 +00:00
// enable source mapping (disable for much smaller files)
2023-01-09 23:23:16 +00:00
devtool: 'inline-source-map',
2023-01-10 00:01:59 +00:00
// auto-generate index.html file with webpack bundles
2023-01-09 23:13:06 +00:00
plugins: [
new HtmlWebpackPlugin({
title: 'Example Webapp',
2023-01-09 23:38:02 +00:00
template: relpath('src/index.html'),
2023-01-09 23:13:06 +00:00
}),
],
output: {
2023-01-09 23:13:06 +00:00
clean: true,
2023-01-09 23:56:03 +00:00
filename: '[name].[contenthash].bundle.js',
2023-01-09 23:38:02 +00:00
path: relpath('dist'),
},
devServer: {
static: relpath('dist'),
},
optimization: {
runtimeChunk: 'single',
2023-01-10 00:01:59 +00:00
// enable caching with vendors in a seperate chunk
moduleIds: 'deterministic',
2023-01-09 23:56:03 +00:00
splitChunks: {
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all',
},
},
},
2023-01-09 23:38:02 +00:00
},
performance: {
// hides the performance warnings for now
2023-01-10 00:01:59 +00:00
// these are especially apparent with source maps enabled
2023-01-09 23:38:02 +00:00
hints: false,
},
2023-01-09 22:35:07 +00:00
module: {
rules: [
2023-01-10 00:22:37 +00:00
// typescript support
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
2023-01-09 22:56:10 +00:00
// sass support with `import './styles.scss'`
2023-01-09 22:35:07 +00:00
{
test: /\.s[ac]ss$/i,
use: ['style-loader', 'css-loader', 'sass-loader'],
},
2023-01-09 22:56:10 +00:00
// css support with `import './styles.css'`
{
2023-01-09 23:01:06 +00:00
test: /\.css$/i,
2023-01-09 22:56:10 +00:00
use: ['style-loader', 'css-loader'],
},
// image support with `import Image from './image.png'`
{
2023-01-10 01:32:22 +00:00
test: /\.(png|svg|jpe?g|gif)$/i,
use: [{ loader: 'file-loader' }],
2023-01-09 22:56:10 +00:00
},
2023-01-09 22:35:07 +00:00
],
},
2023-01-10 00:22:37 +00:00
resolve: {
2023-01-10 00:25:23 +00:00
// need '.tsx', '.ts' for typescript support
// need to include '.js' for webpack-dev-server resolutions, even with typescript support
2023-01-10 00:22:37 +00:00
extensions: ['.tsx', '.ts', '.js'],
},
};