Files
create-react-component-library/webpack.config.ts
Alejandro Lembke Barrientos 6c3dd344e6 PR-733704: update dependencies to latest, bump to v1.4.1
- Bump version 1.4.0 → 1.4.1
- Upgrade Babel 7 → 8 (@babel/core, preset-env, preset-react,
  preset-typescript, register)
- Add ts-node devDependency (webpack-cli needs it to load
  webpack.config.ts now that @babel/register v8 removed .hook)
- Replace __dirname with path.resolve() in webpack.config.ts and
  webpack.cy.config.ts (ESM-safe, no __dirname needed)
- Add npm overrides: force @babel/core ^8 for ts-jest (peerOptional
  conflict) and js-yaml ^4.2.0 to fix GHSA-h67p-54hq-rp68 DoS vuln
- Add babel hook in .storybook/main.js to strip bugfixes option that
  Storybook injects into @babel/preset-env (removed in Babel 8)
- Patch Storybook addons 10.4.3 → 10.4.6, @types/node v25→v26,
  globals v16→v17, sass minor, ts-loader patch, typescript-eslint patch
- 0 npm audit vulnerabilities
2026-06-21 05:40:41 +00:00

102 lines
2.5 KiB
TypeScript

import path from 'path';
import webpack from 'webpack';
import * as dotenv from 'dotenv';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
import nodeExternals from 'webpack-node-externals';
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
import TerserPlugin from 'terser-webpack-plugin';
import ESLintPlugin from 'eslint-webpack-plugin';
import { resolveTsAliases } from 'resolve-ts-aliases';
const dotEnvToParse = dotenv.config();
const libraryName = process.env.LIBRARY_NAME ? process.env.LIBRARY_NAME : 'ui-library';
const externalCss = process.env.EXTERNAL_CSS === 'true' ? true : false;
const externalCssName = process.env.EXTERNAL_CSS_NAME ? process.env.EXTERNAL_CSS_NAME : 'index.css';
const alias = resolveTsAliases(path.resolve('tsconfig.json'));
export default {
entry: './src/components/index.tsx',
externals: [nodeExternals()],
resolve: {
extensions: ['.js', '.jsx','.ts','.tsx', '.json'],
alias,
},
mode: 'production',
output: {
filename: 'index.js',
path: path.resolve('dist'),
library: libraryName,
libraryTarget: 'umd',
globalObject: 'this',
},
plugins: [
new CleanWebpackPlugin(),
...(externalCss === true ? [
new MiniCssExtractPlugin({
filename: externalCssName,
}),
] : []),
new webpack.DefinePlugin({
'process.env': JSON.stringify(dotEnvToParse.parsed),
}),
new ESLintPlugin(),
],
module: {
rules: [
{
test: /\.(ts|tsx)$/,
exclude: [/node_modules/, /\.test\.(ts|tsx)$/, /\.cy\.(ts|tsx)$/],
use: {
loader: 'ts-loader',
options: {
onlyCompileBundledFiles: true,
compilerOptions: {
noEmit: false,
declaration: true,
declarationDir: './dist/types'
}
}
},
},
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: 'babel-loader',
},
{
test: /\.(css|sass|scss)$/,
use: [
externalCss === true ? MiniCssExtractPlugin.loader : 'style-loader',
{
loader: 'css-loader',
options: {
modules: {
namedExport: false,
exportLocalsConvention: 'as-is',
auto: /\.module\.\w+$/i,
}
},
},
'sass-loader',
],
},
{
test: /\.(ttf|otf|eot|woff|woff2)$/,
loader: 'url-loader',
options: {
name: 'assets/fonts/[name].[ext]',
esModule: false,
},
},
]
},
optimization: {
minimize: true,
minimizer: [
new CssMinimizerPlugin(),
new TerserPlugin(),
],
},
};