Skip to content

Commit

Permalink
Merge pull request #36 from j2rong4cn/main
Browse files Browse the repository at this point in the history
更新
  • Loading branch information
traceless authored Aug 25, 2023
2 parents 465619f + 23773b6 commit ad14dde
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 133 deletions.
69 changes: 28 additions & 41 deletions node-proxy/package-lock.json

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

18 changes: 2 additions & 16 deletions node-proxy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"serve": "ts-node -r tsconfig-paths/register app.js",
"test": "echo \"Error: no test specified\" && exit 1",
"webpack": "npx webpack",
"build": "npm run webpack && pkg --compress GZip . ",
"build": "npm run webpack && pkg --compress GZip dist",
"docker": "npm run webpack && sudo docker build -t prophet310/alist-encrypt:beta . ",
"docker-arm": "npm run webpack && sudo docker build -t prophet310/alist-encrypt:beta-arm . ",
"docker-all": "npm run webpack && sudo docker buildx build -t prophet310/alist-encrypt:beta-1.0 --platform=linux/arm64,linux/amd64 . --push "
Expand Down Expand Up @@ -43,20 +43,6 @@
"ts-loader": "^9.4.4",
"ts-node-dev": "^2.0.0",
"webpack": "^5.88.2",
"webpack-cli": "^5.1.4",
"webpack-node-externals": "^3.0.0"
},
"bin": "dist/index.js",
"pkg": {
"options": [
"experimental-modules"
],
"scripts": [
"dist/PRGAThreadCom.js"
],
"assets": [
"dist/public/**/*"
],
"outputPath": "build"
"webpack-cli": "^5.1.4"
}
}
12 changes: 12 additions & 0 deletions node-proxy/pkgconfig.dist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"bin": "index.js",
"pkg": {
"scripts": [
"PRGAThreadCom.js"
],
"assets": [
"public/**/*"
],
"outputPath": "build"
}
}
76 changes: 0 additions & 76 deletions node-proxy/webpack.config.js

This file was deleted.

93 changes: 93 additions & 0 deletions node-proxy/webpack.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import fs from 'fs'
import CopyPlugin from 'copy-webpack-plugin'
import path from 'path'
import TerserPlugin from 'terser-webpack-plugin'
import webpack from 'webpack'

const output = {
filename: '[name].js',
path: path.resolve('./dist'),
}
export default () => {
return <webpack.Configuration>{
entry: { index: path.resolve('./app.js'), PRGAThreadCom: path.resolve('./src/utils/PRGAThreadCom.js') },
output,
module: {
rules: [
{
test: /\.[tj]s$/i,
use: [
{
loader: 'ts-loader',
options: {
transpileOnly: true, // 只做语言转换,而不做类型检查
},
},
],
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.ts', '.js'],
alias: {
'@': path.resolve('./src'),
},
},
plugins: [
new CopyPlugin({
patterns: [
{
from: path.resolve('./public'),
to: path.join(output.path, 'public'),
},
],
}),
new PkgConfig(),
],
target: 'node',
// externals: [nodeExternals()],
mode: 'production',
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
// 是否启用多线程
parallel: true,
// 是否将注释剥离到单独的文件中
extractComments: false,
terserOptions: {
// 是否压缩代码
compress: true,
// 是否压缩标识符
mangle: true,
// 是否保留函数名
keep_fnames: true,
// 是否保留类名
keep_classnames: true,
// format: {
// // 输出格式化
// beautify: true,
// // 保留注释
// comments: true,
// },
},
}),
],
},
}
}

class PkgConfig {
apply(compiler: webpack.Compiler) {
compiler.hooks.afterEmit.tap('DistConfig', () => {
const conf = JSON.parse(fs.readFileSync(path.resolve('./package.json'), 'utf-8'))
const pkg_conf = JSON.parse(fs.readFileSync(path.resolve('./pkgconfig.dist.json'), 'utf-8'))
pkg_conf['name'] = conf['name']
pkg_conf['version'] = conf['version']
const dist_conf_path = path.join(output.path, 'package.json')
fs.writeFileSync(dist_conf_path, JSON.stringify(pkg_conf), { encoding: 'utf-8' })
console.log(dist_conf_path, pkg_conf)
})
}
}

0 comments on commit ad14dde

Please sign in to comment.