Skip to content

Commit 71deb37

Browse files
committed
🎉 starter V1.0
0 parents  commit 71deb37

File tree

8 files changed

+170
-0
lines changed

8 files changed

+170
-0
lines changed

.gitignore

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
/.idea
3+
/.vscode
4+
/docs
5+
/eslint-plugins
6+
7+
# dependencies
8+
/node_modules
9+
/.pnp
10+
.pnp.js
11+
yarn-error.log
12+
yarn.lock
13+
14+
# testing
15+
/coverage
16+
17+
# production
18+
/build
19+
20+
# misc
21+
.DS_Store
22+
.env.local
23+
.env.development.local
24+
.env.test.local
25+
.env.production.local
26+
27+
npm-debug.log*
28+
yarn-debug.log*
29+
yarn-error.log*
30+
31+
.eslintcache

app.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as express from 'express';
2+
import { Request, Response } from 'express';
3+
4+
const app = express();
5+
6+
app.get('/', (req: Request, res: Response) => {
7+
res.status(200).send("Hello Word!");
8+
});
9+
10+
app.listen(5000 );

environment/environment.prod.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const environment = {
2+
production: true,
3+
};

environment/environment.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const environment = {
2+
production: false,
3+
};

package.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "typescript-webpack-starter",
3+
"version": "1.0.0",
4+
"description": "Simple Starter Project Base On Typescript & Webpack",
5+
"main": "app.ts",
6+
"author": "Amirhossein D. Zenoozi",
7+
"license": "ISC",
8+
"scripts": {
9+
"clean": "rimraf build",
10+
"start": "yarn && concurrently \"tsc --watch\" \"nodemon -q build/app.js\""
11+
},
12+
"dependencies": {},
13+
"devDependencies": {
14+
"@types/express": "^4.17.13",
15+
"@types/node": "^16.7.10",
16+
"concurrently": "^6.2.1",
17+
"express": "^4.17.1",
18+
"file-replace-loader": "^1.4.0",
19+
"nodemon": "^2.0.12",
20+
"path": "^0.12.7",
21+
"rimraf": "^3.0.2",
22+
"ts-loader": "^9.2.5",
23+
"typescript": "^4.4.2",
24+
"webpack": "^5.51.1",
25+
"webpack-cli": "^4.8.0",
26+
"webpack-dev-server": "^4.1.0",
27+
"webpack-node-externals": "^3.0.0",
28+
"webpack-shell-plugin-next": "^2.2.2"
29+
}
30+
}

src/sample.module.ts

Whitespace-only changes.

tsconfig.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"noImplicitAny": true,
5+
"removeComments": true,
6+
"preserveConstEnums": true,
7+
"sourceMap": true,
8+
"declaration": true,
9+
"moduleResolution": "node",
10+
"outDir": "./build",
11+
"baseUrl": "./src",
12+
"rootDir": ".",
13+
"paths": {
14+
"src/*": ["./*"]
15+
}
16+
},
17+
"exclude": ["node_modules", "./src/**/*.spec.tsx", "./src/**/*.test.tsx"],
18+
"include": ["./custom.d.ts", "./src/**/*", "app.ts"]
19+
}

webpack/webpack.dev.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
const webpackShellPluginNext = require('webpack-shell-plugin-next');
2+
const nodeExternals = require('webpack-node-externals');
3+
const path = require('path');
4+
5+
const PATHS = {
6+
root: path.resolve(__dirname, '..'),
7+
nodeModules: path.resolve(__dirname, '../node_modules'),
8+
src: path.resolve(__dirname, '../src'),
9+
build: path.resolve(__dirname, '../build'),
10+
dist: path.resolve(__dirname, '../dist'),
11+
};
12+
13+
module.exports = (env = {}) => {
14+
return {
15+
mode: 'production',
16+
target: 'web',
17+
entry: './app.ts',
18+
devtool: 'source-map',
19+
output: {
20+
filename: '[name].js',
21+
publicPath: '/',
22+
path: PATHS.dist,
23+
globalObject: 'this',
24+
},
25+
module: {
26+
rules: [
27+
{
28+
test: /\.(ts|tsx)$/,
29+
exclude: '/node_modules/',
30+
use: [{
31+
loader: 'ts-loader',
32+
}, {
33+
loader: 'file-replace-loader',
34+
options: {
35+
condition: 'always', // <-- Note that the rule applies for all files!
36+
replacement(resourcePath) {
37+
if (resourcePath.endsWith('environment.ts')) {
38+
return path.resolve(__dirname, '../environments/environment.prod.ts');
39+
}
40+
},
41+
async: true,
42+
},
43+
}],
44+
},
45+
],
46+
},
47+
plugins: [
48+
new webpackShellPluginNext({
49+
onBuildEnd: {
50+
scripts: ['yarn run:dev']
51+
}
52+
})
53+
],
54+
optimization: {
55+
minimize: true,
56+
runtimeChunk: 'single',
57+
splitChunks: {
58+
cacheGroups: {
59+
vendor: {
60+
chunks: 'initial',
61+
test: path.resolve(__dirname, '../node_modules'),
62+
name: 'vendor',
63+
enforce: true,
64+
},
65+
},
66+
},
67+
},
68+
externals: [ nodeExternals() ],
69+
resolve: {
70+
alias: PATHS,
71+
extensions: [ '.ts', '.tsx' ],
72+
},
73+
};
74+
};

0 commit comments

Comments
 (0)