Skip to content

Commit

Permalink
feat: Add build for browser
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed Feb 2, 2024
1 parent 88e7268 commit 37f8270
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 7 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@ jobs:
- name: Run tsc
run: |
npm install -g typescript
npm install --save-dev
tsc
- name: Run bundler
- name: Run bundler (tsup)
run: |
npm install -g tsup
tsup
- name: Run bundler (webpack)
run: |
npx webpack
- name: Run tests
run: |
npm install -g jest
Expand Down
Binary file added favicon.ico
Binary file not shown.
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"url": "https://github.com/jcs090218/flx-ts/issues"
},
"scripts": {
"build": "tsup",
"build": "tsup && npx webpack",
"test": "jest"
},
"author": "Jen-Chieh Shen",
Expand All @@ -25,8 +25,11 @@
"@types/jest": "^29.5.11",
"jest": "^29.7.0",
"ts-jest": "^29.1.2",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"tsup": "^8.0.1",
"typescript": "^5.3.3"
"typescript": "^5.3.3",
"webpack": "^5.90.1",
"webpack-cli": "^5.1.4"
}
}
1 change: 1 addition & 0 deletions public/flx.min.js

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

12 changes: 12 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test loading flx in browser</title>
</head>
<body>
<script src="flx.min.js"></script>
<script type="module" src="script.js"></script>
</body>
</html>
5 changes: 5 additions & 0 deletions public/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//import * as Flx from '../dist/flx.global.js';
//import { Flx } from '../dist/bundle.js';

console.log(jcs090218.Flx.Score("buffer-file-name", "bfn"));
//console.log(Flx.Score("buffer-file-name", "bfn"));
4 changes: 2 additions & 2 deletions src/flx.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Util } from './util';

export interface Score {
indices: number[];
indices: Array<number>;
score: number;
tail: number;
}
Expand Down Expand Up @@ -316,7 +316,7 @@ export class Flx {
bestScore = tempScore;

imatch = [];
const indices = [...elem.indices];
const indices = [index, ...elem.indices];
let tail = 0;
if ((caar - 1) === index) {
tail = cddr + 1;
Expand Down
4 changes: 3 additions & 1 deletion tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { defineConfig } from "tsup";

export default defineConfig({
entry: ["src/flx.ts"],
format: ["cjs", "esm"], // Build for commonJS and ESmodules
format: ["cjs", "esm", "iife"],
dts: true, // Generate declaration file (.d.ts)
splitting: false,
sourcemap: true,
clean: true,
//injectStyle: true,
//minify: true,
});
25 changes: 25 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const path = require('path');

module.exports = {
entry: './src/flx.ts',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
output: {
filename: 'flx.min.js',
path: path.resolve(__dirname, 'public'),
iife: false,
libraryTarget: 'var',
library: 'jcs090218',
},
mode: "production",
};

0 comments on commit 37f8270

Please sign in to comment.