Migrated to esbuild

This commit is contained in:
KRTirtho 2021-06-16 13:50:13 +06:00
parent a493e2bc9a
commit 57b565c4a3
7 changed files with 17654 additions and 1540 deletions

View File

@ -1,8 +0,0 @@
{
"presets": [
["@babel/preset-env", { "targets": { "node": "12" } }],
"@babel/preset-typescript",
"@babel/preset-react"
],
"plugins": []
}

42
esbuild.config.mjs Normal file
View File

@ -0,0 +1,42 @@
import { build } from "esbuild";
import { mkdir, copyFile } from "fs/promises";
import { join } from "path";
build({
bundle: true,
outdir: "./dist",
minify: false,
platform: 'node',
target: "es6",
color: true,
jsx: "transform",
sourcemap: true,
tsconfig: "./tsconfig.json",
entryPoints: ["src/index.tsx"],
target: ['node12'],
loader: {
".png": "file",
".jpg": "file",
".gif": "file",
".svg": "file",
".node": "file"
},
plugins: [
{
name: "Native Addon",
setup(build) {
build.onResolve({ filter: /\.node$/ }, async (arg) => {
const pluginName = arg.path.split("/").reverse()[0]
mkdir(join(process.cwd(), "dist"), {recursive: true})
await copyFile(join(arg.resolveDir, arg.path), join(process.cwd(), "dist", pluginName))
return {
external: true,
path: "./"+pluginName,
namespace: "js",
pluginName
}
})
}
},
]
}).catch(() => process.exit(1));

9712
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -7,14 +7,15 @@
"private": true, "private": true,
"scripts": { "scripts": {
"build": "webpack --mode=production", "build": "webpack --mode=production",
"dev": "cross-env TSC_WATCHFILE=UseFsEvents webpack --mode=development", "dev": "nodemon -w src/** -e ts,tsx -x 'node esbuild.config.mjs'",
"start": "qode ./dist/index.js", "check-types": "tsc --noEmit --watch",
"start:watch": "nodemon -e node -w ./*.babelrc -x \"npm start\"", "start": "cd dist && qode index.js",
"start-dev": "concurrently -n \"webpack,spotube\" -p \"{name}-{pid}\" -c \"bgBlue.black.bold,bgGreen.black.bold\" -i --default-input-target spotube \"npm run dev\" \"npm run start:watch\"", "start:watch": "nodemon -w dist -e js -x \"npm start\"",
"debug-dev": "concurrently -n \"webpack,spotube\" -p \"{name}-{pid}\" -c \"bgBlue.black.bold,bgGreen.black.bold\" -i --default-input-target spotube \"npm run dev\" \"npm run debug:watch\"", "start-dev": "concurrently -n \"esbuild,spotube,tsc\" -p \"{name}\" -c \"bgYellow.black.bold,bgGreen.black.bold,bgBlue.black.bold\" -i --default-input-target spotube \"npm run dev\" \"npm run start:watch\" \"npm run check-types\"",
"debug-dev": "concurrently -n \"esbuild,spotube,tsc\" -p \"{name}\" -c \"bgYellow.black.bold,bgGreen.black.bold,bgBlue.black.bold\" -i --default-input-target spotube \"npm run dev\" \"npm run debug:watch\" \"npm run check-types\"",
"start:trace": "qode ./dist/index.js --trace", "start:trace": "qode ./dist/index.js --trace",
"debug": "qode --inspect ./dist/index.js", "debug": "cd dist && qode --inspect index.js",
"debug:watch": "nodemon -e node -w ./*.babelrc -x \"npm run debug\"", "debug:watch": "nodemon -w dist -e js -x \"npm run debug\"",
"pack": "nodegui-packer -p ./dist", "pack": "nodegui-packer -p ./dist",
"pack-deb": "node scripts/build-deb.js", "pack-deb": "node scripts/build-deb.js",
"pack-win32": "powershell.exe -ExecutionPolicy Unrestricted -Command \". '.\\scripts\\build-win32.ps1'\"" "pack-win32": "powershell.exe -ExecutionPolicy Unrestricted -Command \". '.\\scripts\\build-win32.ps1'\""
@ -45,10 +46,6 @@
"ytdl-core": "^4.5.0" "ytdl-core": "^4.5.0"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.13.10",
"@babel/preset-env": "^7.13.12",
"@babel/preset-react": "^7.10.4",
"@babel/preset-typescript": "^7.13.0",
"@nodegui/devtools": "^1.0.1", "@nodegui/devtools": "^1.0.1",
"@nodegui/packer": "^1.4.1", "@nodegui/packer": "^1.4.1",
"@types/color": "^3.0.1", "@types/color": "^3.0.1",
@ -63,10 +60,12 @@
"@types/spotify-web-api-node": "^5.0.0", "@types/spotify-web-api-node": "^5.0.0",
"@types/uuid": "^8.3.0", "@types/uuid": "^8.3.0",
"@types/webpack-env": "^1.15.3", "@types/webpack-env": "^1.15.3",
"babel-loader": "^8.1.0", "@vitejs/plugin-react-refresh": "^1.3.3",
"clean-webpack-plugin": "^3.0.0", "clean-webpack-plugin": "^3.0.0",
"concurrently": "^6.0.0", "concurrently": "^6.0.0",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"esbuild": "^0.12.8",
"esbuild-loader": "^2.13.1",
"file-loader": "^6.2.0", "file-loader": "^6.2.0",
"fork-ts-checker-webpack-plugin": "^6.2.0", "fork-ts-checker-webpack-plugin": "^6.2.0",
"native-addon-loader": "^2.0.1", "native-addon-loader": "^2.0.1",

View File

@ -11,8 +11,13 @@
"alwaysStrict": true, "alwaysStrict": true,
"moduleResolution": "node", "moduleResolution": "node",
"esModuleInterop": true, "esModuleInterop": true,
"skipLibCheck": true "skipLibCheck": true,
"incremental": true
}, },
"include": ["**/*"], "include": [
"exclude": ["**/node_modules/*"] "**/*"
],
"exclude": [
"**/node_modules/*"
]
} }

9357
tsconfig.tsbuildinfo Normal file

File diff suppressed because it is too large Load Diff

View File

@ -2,8 +2,13 @@ const path = require("path");
const webpack = require("webpack"); const webpack = require("webpack");
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin"); const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin"); const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const { ESBuildMinifyPlugin } = require("esbuild-loader")
module.exports = (env, argv) => { module.exports = (env, argv) => {
/**
* @type {import("webpack").Configuration}
*/
const config = { const config = {
mode: "production", mode: "production",
entry: ["./src/index.tsx"], entry: ["./src/index.tsx"],
@ -15,11 +20,30 @@ module.exports = (env, argv) => {
module: { module: {
rules: [ rules: [
{ {
test: /\.(j|t)sx?$/, test: /\.js?$/,
exclude: /node_modules/, exclude: /node_modules/,
use: { loader: 'esbuild-loader',
loader: "babel-loader", options: {
options: { cacheDirectory: true, cacheCompression: false }, loader: 'jsx',
target: 'es2015'
},
},
{
test: /\.tsx?$/,
exclude: /node_modules/,
loader: 'esbuild-loader',
options: {
loader: 'tsx',
target: 'es2015'
},
},
{
test: /\.ts?$/,
exclude: /node_modules/,
loader: 'esbuild-loader',
options: {
loader: 'ts',
target: 'es2015'
}, },
}, },
{ {
@ -46,6 +70,11 @@ module.exports = (env, argv) => {
new webpack.DefinePlugin({"global.GENTLY": false}), new webpack.DefinePlugin({"global.GENTLY": false}),
new CleanWebpackPlugin(), new CleanWebpackPlugin(),
], ],
optimization: {
minimizer: [
new ESBuildMinifyPlugin({target: 'es2015'})
]
},
resolve: { resolve: {
extensions: [".tsx", ".ts", ".js", ".jsx", ".json"], extensions: [".tsx", ".ts", ".js", ".jsx", ".json"],
}, },