mirror of
https://github.com/NeteaseCloudMusicApiEnhanced/api-enhanced.git
synced 2026-02-04 04:43:10 +00:00
ci: Add webpack configuration and license file for bundle.js
- Created webpack.config.js to configure the build process for the application. - Set entry point to app.js and output to precompiled/bundle.js. - Excluded node_modules from the bundle and specified external dependencies. - Added Babel loader for transpiling JavaScript files. - Included a license file for regenerator-runtime in precompiled directory.
This commit is contained in:
parent
2b69e9dda5
commit
d8ecb31f7b
13
package.json
13
package.json
@ -11,7 +11,11 @@
|
||||
"prepare": "husky install",
|
||||
"pkgwin": "pkg . -t node18-win-x64 -C GZip -o bin/app --no-bytecode",
|
||||
"pkglinux": "pkg . -t node18-linux-x64 -C GZip -o bin/app --no-bytecode",
|
||||
"pkgmacos": "pkg . -t node18-macos-x64 -C GZip -o bin/app --no-bytecode"
|
||||
"pkgmacos": "pkg . -t node18-macos-x64 -C GZip -o bin/app --no-bytecode",
|
||||
"build": "webpack --config webpack.config.js",
|
||||
"build:prod": "webpack --mode production --config webpack.config.js",
|
||||
"build:dev": "webpack --mode development --config webpack.config.js",
|
||||
"start:bundle": "node precompiled/bundle.js"
|
||||
},
|
||||
"bin": "./app.js",
|
||||
"pkg": {
|
||||
@ -83,6 +87,8 @@
|
||||
"yargs": "^18.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.28.6",
|
||||
"@babel/preset-env": "^7.28.6",
|
||||
"@eslint/eslintrc": "^3.3.3",
|
||||
"@eslint/js": "^9.39.2",
|
||||
"@types/express": "^5.0.6",
|
||||
@ -91,6 +97,7 @@
|
||||
"@types/node": "25.0.9",
|
||||
"@typescript-eslint/eslint-plugin": "8.46.3",
|
||||
"@typescript-eslint/parser": "8.53.0",
|
||||
"babel-loader": "^10.0.0",
|
||||
"eslint": "9.39.0",
|
||||
"eslint-config-prettier": "10.1.8",
|
||||
"eslint-plugin-html": "8.1.3",
|
||||
@ -104,6 +111,8 @@
|
||||
"pkg": "^5.8.1",
|
||||
"power-assert": "1.6.1",
|
||||
"prettier": "3.7.4",
|
||||
"typescript": "5.9.3"
|
||||
"typescript": "5.9.3",
|
||||
"webpack": "^5.104.1",
|
||||
"webpack-cli": "^6.0.1"
|
||||
}
|
||||
}
|
||||
|
||||
1996
pnpm-lock.yaml
generated
1996
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
51
precompiled/README.md
Normal file
51
precompiled/README.md
Normal file
@ -0,0 +1,51 @@
|
||||
# Webpack Bundle 使用说明
|
||||
|
||||
本项目已配置为使用 Webpack 构建单文件 bundle,放置在 `./precompiled` 目录下。
|
||||
|
||||
## 构建命令
|
||||
|
||||
```bash
|
||||
# 开发模式构建
|
||||
npm run build:dev
|
||||
|
||||
# 生产模式构建(默认)
|
||||
npm run build
|
||||
# 或
|
||||
npm run build:prod
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
由于本项目使用了动态模块加载(特别是 `./module` 目录下的 API 模块),完全的单文件打包会有一些限制:
|
||||
|
||||
1. Webpack 生成的 bundle 文件 (`precompiled/bundle.js`) 依赖于项目根目录的 `module` 文件夹来动态加载 API 模块
|
||||
2. 因此,部署时需要同时包含 `bundle.js` 和 `module` 文件夹
|
||||
3. 完整的部署结构应如下:
|
||||
```
|
||||
project/
|
||||
├── precompiled/
|
||||
│ └── bundle.js
|
||||
├── module/
|
||||
│ ├── album_detail.js
|
||||
│ ├── artist_album.js
|
||||
│ └── ... (所有API模块文件)
|
||||
├── node_modules/
|
||||
└── ... (其他依赖文件夹)
|
||||
```
|
||||
|
||||
## 运行
|
||||
|
||||
```bash
|
||||
node precompiled/bundle.js
|
||||
```
|
||||
|
||||
## 替代方案
|
||||
|
||||
如果您需要真正的单文件部署,可以考虑使用项目中已有的 pkg 配置:
|
||||
```bash
|
||||
npm run pkgwin # Windows
|
||||
npm run pkglinux # Linux
|
||||
npm run pkgmacos # macOS
|
||||
```
|
||||
|
||||
这些命令会创建真正的单文件可执行程序,其中包含了所有必要的依赖。
|
||||
2
precompiled/bundle.js
Normal file
2
precompiled/bundle.js
Normal file
File diff suppressed because one or more lines are too long
1
precompiled/bundle.js.LICENSE.txt
Normal file
1
precompiled/bundle.js.LICENSE.txt
Normal file
@ -0,0 +1 @@
|
||||
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
||||
71
webpack.config.js
Normal file
71
webpack.config.js
Normal file
@ -0,0 +1,71 @@
|
||||
const path = require('path');
|
||||
|
||||
module.exports = {
|
||||
entry: './app.js',
|
||||
target: 'node',
|
||||
output: {
|
||||
path: path.resolve(__dirname, 'precompiled'),
|
||||
filename: 'bundle.js',
|
||||
libraryTarget: 'commonjs2',
|
||||
},
|
||||
resolve: {
|
||||
extensions: ['.js', '.json'],
|
||||
},
|
||||
// 排除所有node_modules中的依赖,因为它们在运行时会被require
|
||||
externals: [
|
||||
// 项目依赖的所有外部模块
|
||||
'express',
|
||||
'fs',
|
||||
'path',
|
||||
'os',
|
||||
'child_process',
|
||||
'crypto-js',
|
||||
'dotenv',
|
||||
'express-fileupload',
|
||||
'md5',
|
||||
'music-metadata',
|
||||
'node-forge',
|
||||
'pac-proxy-agent',
|
||||
'qrcode',
|
||||
'safe-decode-uri-component',
|
||||
'tunnel',
|
||||
'xml2js',
|
||||
'yargs',
|
||||
'axios',
|
||||
'@neteasecloudmusicapienhanced/unblockmusic-utils',
|
||||
/\.node$/, // 排除.node文件
|
||||
],
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.js$/,
|
||||
use: {
|
||||
loader: 'babel-loader',
|
||||
options: {
|
||||
presets: ['@babel/preset-env'],
|
||||
},
|
||||
},
|
||||
exclude: /node_modules/,
|
||||
},
|
||||
],
|
||||
},
|
||||
mode: 'production',
|
||||
optimization: {
|
||||
minimize: true,
|
||||
},
|
||||
stats: {
|
||||
errorDetails: true
|
||||
},
|
||||
// 为动态模块提供上下文
|
||||
plugins: [
|
||||
new (require('webpack')).ContextReplacementPlugin(
|
||||
/util[\/\\]request/, // 针对request模块路径
|
||||
path.resolve(__dirname)
|
||||
)
|
||||
],
|
||||
// 避免对Node.js内置模块的警告
|
||||
node: {
|
||||
__dirname: false,
|
||||
__filename: false,
|
||||
}
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user