Migrate to webpack

This commit is contained in:
Manuel Thalmann 2022-12-02 00:58:56 +01:00
parent 07a33c8ee4
commit 4d45e8e576
9 changed files with 1248 additions and 12 deletions

View file

@ -12,7 +12,7 @@ module.exports = {
parserOptions: { parserOptions: {
project: [ project: [
join(__dirname, "tsconfig.app.json"), join(__dirname, "tsconfig.app.json"),
join(__dirname, "tsconfig.eslint.json"), join(__dirname, "misc.tsconfig.json"),
join(__dirname, "src", "tests", "tsconfig.json") join(__dirname, "src", "tests", "tsconfig.json")
] ]
} }

View file

@ -157,6 +157,9 @@ tsconfig.*.json
.drone.yml .drone.yml
.woodpecker.yml .woodpecker.yml
# Build System
webpack.config.ts
# Temporary release-assets # Temporary release-assets
.tagName.txt .tagName.txt
.tagHeading.txt .tagHeading.txt

4
.vscode/tasks.json vendored
View file

@ -11,7 +11,7 @@
"kind": "build", "kind": "build",
"isDefault": true "isDefault": true
}, },
"problemMatcher": "$tsc-watch", "problemMatcher": "$ts-webpack-watch",
"isBackground": true, "isBackground": true,
"presentation": { "presentation": {
"reveal": "never" "reveal": "never"
@ -21,7 +21,7 @@
"label": "Rebuild", "label": "Rebuild",
"type": "npm", "type": "npm",
"script": "rebuild", "script": "rebuild",
"problemMatcher": "$tsc", "problemMatcher": "$ts-webpack",
"presentation": { "presentation": {
"reveal": "never" "reveal": "never"
} }

View file

@ -5,6 +5,7 @@
"checkJs": true "checkJs": true
}, },
"include": [ "include": [
"./.eslintrc.cjs" "./.eslintrc.cjs",
"./webpack.config.ts"
] ]
} }

1144
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -19,10 +19,12 @@
"access": "public" "access": "public"
}, },
"scripts": { "scripts": {
"build": "tsc -b tsconfig.build.json", "webpack": "cross-env NODE_OPTIONS=\"--loader ts-node/esm\" webpack",
"build": "npm run webpack --",
"compile": "tsc -b tsconfig.build.json",
"rebuild": "npm run clean && npm run build", "rebuild": "npm run clean && npm run build",
"watch": "npm run build -- --watch", "watch": "npm run build -- --watch",
"clean": "npm run build -- --clean && rimraf ./lib", "clean": "npm run compile -- --clean && rimraf ./lib",
"lint": "eslint --max-warnings 0 ./src .eslintrc.cjs", "lint": "eslint --max-warnings 0 ./src .eslintrc.cjs",
"lint-ide": "npm run lint || exit 0", "lint-ide": "npm run lint || exit 0",
"test": "mocha", "test": "mocha",
@ -37,11 +39,17 @@
"@manuth/tsconfig": "^3.0.2", "@manuth/tsconfig": "^3.0.2",
"@types/mocha": "^9.1.1", "@types/mocha": "^9.1.1",
"@types/node": "^18.7.18", "@types/node": "^18.7.18",
"@types/webpack": "^5.28.0",
"cross-env": "^7.0.3",
"eslint": "^8.23.1", "eslint": "^8.23.1",
"mocha": "^10.0.0", "mocha": "^10.0.0",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"source-map-support": "^0.5.21", "source-map-support": "^0.5.21",
"ts-loader": "^9.4.2",
"ts-node": "^10.9.1",
"ts-patch": "^2.0.2", "ts-patch": "^2.0.2",
"typescript": "^4.8.3" "typescript": "^4.8.3",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.0"
} }
} }

View file

@ -2,7 +2,8 @@
"extends": "../../tsconfig.base.json", "extends": "../../tsconfig.base.json",
"compilerOptions": { "compilerOptions": {
"rootDir": "..", "rootDir": "..",
"outDir": "../../lib" "outDir": "../../lib",
"composite": true
}, },
"include": [ "include": [
"./**/*" "./**/*"

View file

@ -6,7 +6,7 @@
"path": "./tsconfig.build.json" "path": "./tsconfig.build.json"
}, },
{ {
"path": "./tsconfig.eslint.json" "path": "./misc.tsconfig.json"
} }
] ]
} }

85
webpack.config.ts Normal file
View file

@ -0,0 +1,85 @@
import { resolve } from "path";
import { fileURLToPath } from "url";
import exports, { Configuration } from "webpack";
const { WatchIgnorePlugin } = exports;
let dirname = fileURLToPath(new URL(".", import.meta.url));
let generator = (env: any, argv: any): Configuration[] =>
{
return [
{
target: "web",
mode: env.production ? "production" : "development",
entry: {
main: "./src/index.ts"
},
output: {
filename: "[name].js",
path: resolve(dirname, "lib"),
devtoolFallbackModuleFilenameTemplate: "../[resource-path]",
libraryTarget: "module",
chunkFormat: "module",
environment: {
dynamicImport: true
}
},
devtool: "source-map",
resolve: {
extensions: [
".ts",
".js"
],
extensionAlias: {
".js": [
".js",
".ts"
],
".mjs": [
".mjs",
".mts"
],
".cjs": [
".cjs",
".cts"
]
}
},
plugins: [
new WatchIgnorePlugin(
{
paths: [
/\.d\.ts$/
]
})
],
module: {
rules: [
{
test: /\.([cm]?ts|tsx)$/,
exclude: /node_modules/,
use: [
{
loader: "ts-loader",
options: {
configFile: resolve(dirname, "tsconfig.build.json"),
projectReferences: true,
compilerOptions: {
outDir: resolve(dirname, "lib", "temp")
}
}
}
]
}
]
},
experiments: {
outputModule: true
}
}
];
};
// eslint-disable-next-line import/no-default-export
export default generator;