Skip to content

Commit 97d8c8c

Browse files
Add basic demo built by Webpack
1 parent 1375185 commit 97d8c8c

File tree

9 files changed

+709
-15
lines changed

9 files changed

+709
-15
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
/coverage/
2+
/demo/lib/
23
/lib/
4+
webpack.config.js

demo/src/index.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<html>
2+
<head>
3+
<style>
4+
body,
5+
input {
6+
font-size: 1.5em;
7+
}
8+
input {
9+
text-align: center;
10+
width: 5em;
11+
}
12+
[readonly] {
13+
background-color: lightgray;
14+
}
15+
</style>
16+
</head>
17+
<body>
18+
<input type="number" id="num1" value="0" required />
19+
+
20+
<input type="number" id="num2" value="0" required />
21+
=
22+
<input readonly id="sum" value="0" />
23+
24+
<script type="text/javascript" src="demo.js"></script>
25+
</body>
26+
</html>

demo/src/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import add from '../../src';
2+
3+
const num1 = document.getElementById('num1') as HTMLInputElement;
4+
const num2 = document.getElementById('num2') as HTMLInputElement;
5+
const sum = document.getElementById('sum') as HTMLInputElement;
6+
7+
function recalculate() {
8+
const value1 = parseFloat(num1.value);
9+
const value2 = parseFloat(num2.value);
10+
sum.value = add(value1, value2).toString();
11+
}
12+
13+
num1.addEventListener('keyup', recalculate);
14+
num2.addEventListener('keyup', recalculate);

demo/tsconfig.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"compilerOptions": {
3+
"lib": ["dom", "es5"],
4+
"noEmit": true,
5+
"outDir": "./lib",
6+
"rootDir": "./src",
7+
"tsBuildInfoFile": "./lib/demo.tsbuildinfo"
8+
},
9+
"extends": "../tsconfig.json",
10+
"include": ["src"],
11+
"references": [{ "path": "../src" }]
12+
}

demo/webpack.config.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/// <reference types="node" />
2+
const { resolve } = require('path');
3+
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
4+
const CopyPlugin = require("copy-webpack-plugin");
5+
6+
module.exports = {
7+
entry: './demo/src/index.ts',
8+
mode: 'production',
9+
plugins: [
10+
new CleanWebpackPlugin(),
11+
new CopyPlugin({
12+
patterns: [
13+
{
14+
context: resolve(__dirname, 'src'),
15+
from: '**/*.html',
16+
},
17+
],
18+
}),
19+
],
20+
module: {
21+
rules: [
22+
{
23+
exclude: /node_modules/,
24+
test: /\.ts$/,
25+
use: [
26+
{
27+
loader: 'ts-loader',
28+
options: {
29+
compilerOptions: { noEmit: false },
30+
configFile: resolve(__dirname, './tsconfig.json'),
31+
projectReferences: true,
32+
},
33+
},
34+
],
35+
}
36+
],
37+
},
38+
output: {
39+
filename: 'demo.js',
40+
path: resolve(__dirname, './lib'),
41+
},
42+
resolve: {
43+
extensions: ['.ts', '.js'],
44+
},
45+
};

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
2-
collectCoverageFrom: ['**/src/**/?*.(js|ts)', '!**/src/**/?*.d.ts'],
2+
collectCoverageFrom: ['./src/**/?*.(js|ts)', '!**/src/**/?*.d.ts'],
33
restoreMocks: true,
44
globals: {
55
'ts-jest': {

package.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,32 @@
1010
"node": ">=14"
1111
},
1212
"scripts": {
13-
"build": "tsc -b --clean && tsc -b",
13+
"build": "run-s build:*",
14+
"build:src": "tsc -b --clean && tsc -b",
15+
"build:demo": "wp --config demo/webpack.config.js",
1416
"lint": "tsc -b && eslint . --report-unused-disable-directives",
17+
"start": "npm run build:demo && npx http-server ./demo/lib/ -c-1 -p 80",
1518
"test": "jest --coverage"
1619
},
1720
"devDependencies": {
1821
"@types/jest": "^26.0.5",
1922
"@typescript-eslint/eslint-plugin": "^4.23.0",
2023
"@typescript-eslint/parser": "^4.23.0",
24+
"clean-webpack-plugin": "^4.0.0-alpha.0",
25+
"copy-webpack-plugin": "^9.0.0",
2126
"eslint": "^7.26.0",
2227
"eslint-config-airbnb-base": "^14.2.1",
2328
"eslint-config-prettier": "^6.11.0",
2429
"eslint-import-resolver-typescript": "^2.0.0",
2530
"eslint-plugin-import": "^2.23.0",
2631
"eslint-plugin-jest": "^23.18.0",
2732
"jest": "^26.6.3",
33+
"npm-run-all": "^4.1.5",
2834
"prettier": "^2.0.5",
2935
"ts-jest": "^26.5.6",
30-
"typescript": "^4.2.4"
36+
"ts-loader": "^9.2.1",
37+
"typescript": "^4.2.4",
38+
"webpack": "^5.37.1",
39+
"webpack-nano": "^1.1.1"
3140
}
3241
}

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
},
2222
"files": [],
2323
"references": [
24+
{ "path": "./demo" },
2425
{ "path": "./src" },
2526
{ "path": "./src/tsconfig.test.json" }
2627
]

0 commit comments

Comments
 (0)