Skip to content

Instantly share code, notes, and snippets.

@Berkays
Created January 27, 2022 19:42
Show Gist options
  • Save Berkays/1c77706ae7dd03fc25710328990cbcf8 to your computer and use it in GitHub Desktop.
Save Berkays/1c77706ae7dd03fc25710328990cbcf8 to your computer and use it in GitHub Desktop.
Webpack/Typescript/React Starter Template
// PLACE INSIDE /src folder
export function App() {}
// PLACE INSIDE /src folder
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Sample</title>
<style>
html,
body,
#app {
min-height: 100;
height: 100%;
margin: 0;
}
</style>
</head>
<body>
<div id="app"></div>
</body>
</html>
// PLACE INSIDE /src folder
import ReactDOM from "react-dom";
import { App } from "./App";
const app = document.getElementById("app");
ReactDOM.render(<App />, app);
{
"name": "sample",
"scripts": {
"start": "webpack serve --config ./webpack.config.js --mode development"
},
"devDependencies": {
"@types/react": "^17.0.38",
"@types/react-dom": "^17.0.11",
"html-webpack-plugin": "^5.5.0",
"ts-loader": "^9.2.6",
"webpack": "^5.67.0",
"webpack-cli": "^4.9.2",
"webpack-dev-server": "^4.7.3"
},
"dependencies": {
"react": "^17.0.2",
"react-dom": "^17.0.2",
}
}
{
"compilerOptions": {
"jsx": "react-jsx",
"esModuleInterop": true,
"noImplicitAny": true,
"allowSyntheticDefaultImports": true,
"module": "es6",
"target": "es5",
"moduleResolution": "node"
},
"include": [
"src"
]
}
const path = require('path');
const HTMLWebpackPlugin = require("html-webpack-plugin");
module.exports = {
entry: path.resolve(__dirname, './src/index.tsx'),
module: {
rules: [
{
test: /\.(ts|tsx)$/,
exclude: /node_modules/,
use: ['ts-loader'],
}
],
},
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
modules: ['src', 'node_modules'],
alias: {
"react/jsx-dev-runtime": "react/jsx-dev-runtime.js",
"react/jsx-runtime": "react/jsx-runtime.js",
}
},
plugins: [new HTMLWebpackPlugin({ template: "./src/index.html" })],
output: {
path: path.resolve(__dirname, './dist'),
filename: 'bundle.js',
},
devServer: {
static: {
directory: path.join(__dirname, 'dist'),
},
open: true
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment