Skip to content

Commit

Permalink
Convert webpack config to ts
Browse files Browse the repository at this point in the history
  • Loading branch information
dli7319 committed Feb 1, 2025
1 parent b70d4ac commit 36bd03f
Show file tree
Hide file tree
Showing 4 changed files with 200 additions and 9 deletions.
191 changes: 187 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.10",
"@types/clamp": "^1.0.1",
"@types/color-convert": "^2.0.0",
"@types/node": "^22.13.0",
"@types/react": "^18.0.28",
"@types/react-copy-to-clipboard": "^5.0.4",
"@types/react-dom": "^18.0.11",
"@types/webpack": "^5.28.5",
"clamp": "^1.0.1",
"color-convert": "^2.0.1",
"css-loader": "^6.7.3",
Expand All @@ -39,6 +41,7 @@
"react-refresh": "^0.14.0",
"style-loader": "^3.3.1",
"ts-loader": "^9.5.2",
"ts-node": "^10.9.2",
"typescript": "^4.9.5",
"webpack": "^5.94.0",
"webpack-cli": "^4.9.2",
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"noUnusedParameters": true, // Report errors on unused parameters
"incremental": true, // Enable incremental compilation by reading/writing information from prior compilations to a file on disk
"noFallthroughCasesInSwitch": true, // Report errors for fallthrough cases in switch statement
"experimentalDecorators": true
"experimentalDecorators": true,
"types": ["node"]
},
"include": [
"src/**/*" // *** The files TypeScript should type check ***
Expand Down
12 changes: 8 additions & 4 deletions webpack.config.js → webpack.config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
const path = require('path');
import path from 'path';
import webpack from 'webpack';
import 'webpack-dev-server';

const isDevelopment = process.env.NODE_ENV !== 'production';

module.exports = {
const config: webpack.Configuration = {
mode: isDevelopment ? 'development' : 'production',
entry: './src/index.tsx',
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist'),
path: path.resolve(import.meta.dirname, 'dist'),
},
module: {
rules: [
Expand All @@ -33,8 +35,10 @@ module.exports = {
devServer: {
hot: true,
static: {
directory: path.join(__dirname, 'dist'),
directory: path.join(import.meta.dirname, 'dist'),
},
compress: true,
},
};

export default config;

0 comments on commit 36bd03f

Please sign in to comment.