Skip to content

Commit

Permalink
build(webpack): add webpack to bundle all the files to a single file
Browse files Browse the repository at this point in the history
  • Loading branch information
tks18 committed Nov 30, 2021
1 parent 6ad0e4a commit d6ae2d9
Show file tree
Hide file tree
Showing 6 changed files with 740 additions and 20 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
tests
dist
webpack.config.js
.eslintrc.js
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"test:single": "set NODE_ENV=test && ts-mocha -r 'tests/require'",
"test:report": "set NODE_ENV=test && ts-mocha --paths tests/api/**/*.spec.ts -r 'tests/require' --reporter mocha-simple-html-reporter --reporter-options output=test-report.html",
"serve:dev": "set NODE_ENV=development && nodemon --ignore tests/ -r tsconfig-paths/register app.ts",
"build:tsc": "set NODE_ENV=production && tsc && tsc-alias",
"build:tsc": "set NODE_ENV=production && webpack",
"build:prepare": "bash ./scripts/prepare-build.sh",
"start": "set NODE_ENV=production && node app.js"
},
Expand Down Expand Up @@ -102,10 +102,15 @@
"mocha-simple-html-reporter": "^2.0.0",
"mocha-steps": "^1.3.0",
"standard-version": "^9.3.2",
"ts-loader": "^9.2.6",
"ts-mocha": "^8.0.0",
"tsc-alias": "^1.4.1",
"tsconfig-paths": "^3.12.0",
"typescript": "^4.5.2"
"tsconfig-paths-webpack-plugin": "^3.5.2",
"typescript": "^4.5.2",
"webpack": "^5.64.4",
"webpack-cli": "^4.9.1",
"webpack-node-externals": "^3.0.0"
},
"config": {
"commitizen": {
Expand Down
2 changes: 1 addition & 1 deletion scripts/obfuscate.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

javascript-obfuscator ./out --output ./dist --target=node
javascript-obfuscator ./out --output ./dist --target=node --compact=true --string-array=true --string-array-rotate=true --string-array-shuffle=true --numbers-to-expressions=true --simplify=true --split-strings=true --split-strings-chunk-length=5
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "ES5",
"target": "ES6",
"module": "commonjs",
"outDir": "./out",
"rootDir": "./",
Expand All @@ -25,5 +25,5 @@
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"exclude": ["./tests/*"]
"exclude": ["./tests/*", "./webpack.config.js"]
}
30 changes: 30 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const nodeExternals = require('webpack-node-externals');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const path = require('path');

module.exports = {
entry: './app.ts',
mode: 'production',
output: {
path: path.resolve(__dirname, 'out'),
filename: 'app.js',
libraryTarget: 'this',
},
target: 'node',
module: {
rules: [
{
test: /(\.tsx|\.ts)?$/,
loader: 'ts-loader',
options: {
transpileOnly: true,
},
},
],
},
resolve: {
extensions: ['.ts', '.tsx', '.js'],
plugins: [new TsconfigPathsPlugin()],
},
externals: [nodeExternals()],
};
Loading

0 comments on commit d6ae2d9

Please sign in to comment.