Revert vite build
|
@ -0,0 +1,9 @@
|
|||
const isDev = process.env.NODE_ENV === 'development'
|
||||
|
||||
module.exports = {
|
||||
modules: {
|
||||
localIdentName: isDev ? '[path][name]__[local]--[hash:base64:5]' : '[hash:base64:5]',
|
||||
exportLocalsConvention: 'camelCase',
|
||||
},
|
||||
sourceMap: isDev,
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
const path = require('path')
|
||||
const ESLintPlugin = require('eslint-webpack-plugin')
|
||||
|
||||
const isDev = process.env.NODE_ENV === 'development'
|
||||
|
||||
module.exports = {
|
||||
target: 'electron-main',
|
||||
output: {
|
||||
filename: '[name].js',
|
||||
library: {
|
||||
type: 'commonjs2',
|
||||
},
|
||||
path: path.join(__dirname, '../../dist'),
|
||||
},
|
||||
externals: {
|
||||
'font-list': 'font-list',
|
||||
'better-sqlite3': 'better-sqlite3',
|
||||
'electron-font-manager': 'electron-font-manager',
|
||||
bufferutil: 'bufferutil',
|
||||
'utf-8-validate': 'utf-8-validate',
|
||||
'qrc_decode.node': isDev ? path.join(__dirname, '../../build/Release/qrc_decode.node') : path.join('../build/Release/qrc_decode.node'),
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
'@main': path.join(__dirname, '../../src/main'),
|
||||
'@renderer': path.join(__dirname, '../../src/renderer'),
|
||||
'@lyric': path.join(__dirname, '../../src/renderer-lyric'),
|
||||
'@common': path.join(__dirname, '../../src/common'),
|
||||
},
|
||||
extensions: ['.tsx', '.ts', '.js', '.mjs', '.json', '.node'],
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.node$/,
|
||||
use: 'node-loader',
|
||||
},
|
||||
{
|
||||
test: /\.tsx?$/,
|
||||
use: 'ts-loader',
|
||||
exclude: /node_modules/,
|
||||
},
|
||||
],
|
||||
},
|
||||
plugins: [
|
||||
new ESLintPlugin(),
|
||||
],
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
const path = require('path')
|
||||
const { merge } = require('webpack-merge')
|
||||
const webpack = require('webpack')
|
||||
|
||||
const baseConfig = require('./webpack.config.base')
|
||||
|
||||
|
||||
module.exports = merge(baseConfig, {
|
||||
mode: 'development',
|
||||
entry: {
|
||||
main: path.join(__dirname, '../../src/main/index-dev.ts'),
|
||||
// 'dbService.worker': path.join(__dirname, '../../src/main/worker/dbService/index.ts'),
|
||||
},
|
||||
devtool: 'eval-source-map',
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
'process.env': {
|
||||
NODE_ENV: '"development"',
|
||||
},
|
||||
webpackStaticPath: `"${path.join(__dirname, '../../src/static').replace(/\\/g, '\\\\')}"`,
|
||||
webpackUserApiPath: `"${path.join(__dirname, '../../src/main/modules/userApi').replace(/\\/g, '\\\\')}"`,
|
||||
}),
|
||||
],
|
||||
performance: {
|
||||
maxEntrypointSize: 1024 * 1024 * 50,
|
||||
maxAssetSize: 1024 * 1024 * 30,
|
||||
},
|
||||
})
|
|
@ -0,0 +1,49 @@
|
|||
const path = require('path')
|
||||
const { merge } = require('webpack-merge')
|
||||
const webpack = require('webpack')
|
||||
const CopyWebpackPlugin = require('copy-webpack-plugin')
|
||||
|
||||
const baseConfig = require('./webpack.config.base')
|
||||
|
||||
// const { dependencies } = require('../../package.json')
|
||||
|
||||
const buildConfig = require('../webpack-build-config')
|
||||
|
||||
|
||||
module.exports = merge(baseConfig, {
|
||||
mode: 'production',
|
||||
entry: {
|
||||
main: path.join(__dirname, '../../src/main/index.ts'),
|
||||
// 'dbService.worker': path.join(__dirname, '../../src/main/worker/dbService/index.ts'),
|
||||
},
|
||||
node: {
|
||||
__dirname: false,
|
||||
__filename: false,
|
||||
},
|
||||
plugins: [
|
||||
new CopyWebpackPlugin({
|
||||
patterns: [
|
||||
{
|
||||
from: path.join(__dirname, '../../src/main/modules/userApi/renderer/user-api.html'),
|
||||
to: path.join(__dirname, '../../dist/userApi/renderer/user-api.html'),
|
||||
},
|
||||
{
|
||||
from: path.join(__dirname, '../../src/common/theme/images/*').replace(/\\/g, '/'),
|
||||
to: path.join(__dirname, '../../dist/theme_images/[name][ext]'),
|
||||
},
|
||||
],
|
||||
}),
|
||||
new webpack.DefinePlugin({
|
||||
'process.env': {
|
||||
NODE_ENV: '"production"',
|
||||
},
|
||||
}),
|
||||
],
|
||||
performance: {
|
||||
maxEntrypointSize: 1024 * 1024 * 10,
|
||||
maxAssetSize: 1024 * 1024 * 20,
|
||||
},
|
||||
optimization: {
|
||||
minimize: buildConfig.minimize,
|
||||
},
|
||||
})
|
|
@ -1,3 +1,146 @@
|
|||
process.env.NODE_ENV = 'production'
|
||||
|
||||
require('./vite/pack')
|
||||
const chalk = require('chalk')
|
||||
const del = require('del')
|
||||
const webpack = require('webpack')
|
||||
const Spinnies = require('spinnies')
|
||||
|
||||
const mainConfig = './main/webpack.config.prod'
|
||||
const rendererConfig = './renderer/webpack.config.prod'
|
||||
const rendererLyricConfig = './renderer-lyric/webpack.config.prod'
|
||||
const rendererScriptConfig = './renderer-scripts/webpack.config.prod'
|
||||
|
||||
const errorLog = chalk.bgRed.white(' ERROR ') + ' '
|
||||
const okayLog = chalk.bgGreen.white(' OKAY ') + ' '
|
||||
|
||||
const { Worker, isMainThread, parentPort } = require('worker_threads')
|
||||
|
||||
|
||||
function build() {
|
||||
console.time('build')
|
||||
del.sync(['dist/**', 'build/**'])
|
||||
|
||||
const spinners = new Spinnies({ color: 'blue' })
|
||||
spinners.add('main', { text: 'main building' })
|
||||
spinners.add('renderer', { text: 'renderer building' })
|
||||
spinners.add('renderer-lyric', { text: 'renderer-lyric building' })
|
||||
spinners.add('renderer-scripts', { text: 'renderer-scripts building' })
|
||||
let results = ''
|
||||
|
||||
// m.on('success', () => {
|
||||
// process.stdout.write('\x1B[2J\x1B[0f')
|
||||
// console.log(`\n\n${results}`)
|
||||
// console.log(`${okayLog}take it away ${chalk.yellow('`electron-builder`')}\n`)
|
||||
// process.exit()
|
||||
// })
|
||||
function handleSuccess() {
|
||||
process.stdout.write('\x1B[2J\x1B[0f')
|
||||
console.log(`\n\n${results}`)
|
||||
console.log(`${okayLog}take it away ${chalk.yellow('`electron-builder`')}\n`)
|
||||
console.timeEnd('build')
|
||||
process.exit()
|
||||
}
|
||||
|
||||
Promise.all([
|
||||
pack(mainConfig).then(result => {
|
||||
results += result + '\n\n'
|
||||
spinners.succeed('main', { text: 'main build success!' })
|
||||
}).catch(err => {
|
||||
spinners.fail('main', { text: 'main build fail :(' })
|
||||
console.log(`\n ${errorLog}failed to build main process`)
|
||||
console.error(`\n${err}\n`)
|
||||
process.exit(1)
|
||||
}),
|
||||
pack(rendererConfig).then(result => {
|
||||
results += result + '\n\n'
|
||||
spinners.succeed('renderer', { text: 'renderer build success!' })
|
||||
}).catch(err => {
|
||||
spinners.fail('renderer', { text: 'renderer build fail :(' })
|
||||
console.log(`\n ${errorLog}failed to build renderer process`)
|
||||
console.error(`\n${err}\n`)
|
||||
process.exit(1)
|
||||
}),
|
||||
pack(rendererLyricConfig).then(result => {
|
||||
results += result + '\n\n'
|
||||
spinners.succeed('renderer-lyric', { text: 'renderer-lyric build success!' })
|
||||
}).catch(err => {
|
||||
spinners.fail('renderer-lyric', { text: 'renderer-lyric build fail :(' })
|
||||
console.log(`\n ${errorLog}failed to build renderer-lyric process`)
|
||||
console.error(`\n${err}\n`)
|
||||
process.exit(1)
|
||||
}),
|
||||
pack(rendererScriptConfig).then(result => {
|
||||
results += result + '\n\n'
|
||||
spinners.succeed('renderer-scripts', { text: 'renderer-scripts build success!' })
|
||||
}).catch(err => {
|
||||
spinners.fail('renderer-scripts', { text: 'renderer-scripts build fail :(' })
|
||||
console.log(`\n ${errorLog}failed to build renderer-scripts process`)
|
||||
console.error(`\n${err}\n`)
|
||||
process.exit(1)
|
||||
}),
|
||||
]).then(handleSuccess)
|
||||
}
|
||||
|
||||
function pack(config) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const worker = new Worker(__filename)
|
||||
const subChannel = new MessageChannel()
|
||||
worker.postMessage({ port: subChannel.port1, config }, [subChannel.port1])
|
||||
subChannel.port2.on('message', ({ status, message }) => {
|
||||
switch (status) {
|
||||
case 'success': return resolve(message)
|
||||
case 'error': return reject(message)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function runPack(config) {
|
||||
return new Promise((resolve, reject) => {
|
||||
config = require(config)
|
||||
config.mode = 'production'
|
||||
webpack(config, (err, stats) => {
|
||||
if (err) reject(err.stack || err)
|
||||
else if (stats.hasErrors()) {
|
||||
let err = ''
|
||||
|
||||
stats.toString({
|
||||
chunks: false,
|
||||
modules: false,
|
||||
colors: true,
|
||||
})
|
||||
.split(/\r?\n/)
|
||||
.forEach(line => {
|
||||
err += ` ${line}\n`
|
||||
})
|
||||
|
||||
reject(err)
|
||||
} else {
|
||||
resolve(stats.toString({
|
||||
chunks: false,
|
||||
colors: true,
|
||||
}))
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
if (isMainThread) build()
|
||||
else {
|
||||
parentPort.once('message', ({ port, config }) => {
|
||||
// assert(port instanceof MessagePort)
|
||||
runPack(config).then((result) => {
|
||||
port.postMessage({
|
||||
status: 'success',
|
||||
message: result,
|
||||
})
|
||||
}).catch((err) => {
|
||||
port.postMessage({
|
||||
status: 'error',
|
||||
message: err,
|
||||
})
|
||||
}).finally(() => {
|
||||
port.close()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -0,0 +1,152 @@
|
|||
const path = require('path')
|
||||
const { VueLoaderPlugin } = require('vue-loader')
|
||||
const HTMLPlugin = require('html-webpack-plugin')
|
||||
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
||||
const ESLintPlugin = require('eslint-webpack-plugin')
|
||||
|
||||
const vueLoaderConfig = require('../vue-loader.config')
|
||||
const { mergeCSSLoader } = require('../utils')
|
||||
|
||||
const isDev = process.env.NODE_ENV === 'development'
|
||||
|
||||
module.exports = {
|
||||
target: 'electron-renderer',
|
||||
entry: {
|
||||
'renderer-lyric': path.join(__dirname, '../../src/renderer-lyric/main.ts'),
|
||||
},
|
||||
output: {
|
||||
filename: '[name].js',
|
||||
library: {
|
||||
type: 'commonjs2',
|
||||
},
|
||||
path: path.join(__dirname, '../../dist'),
|
||||
publicPath: '',
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
'@root': path.join(__dirname, '../../src'),
|
||||
'@main': path.join(__dirname, '../../src/main'),
|
||||
'@renderer': path.join(__dirname, '../../src/renderer'),
|
||||
'@lyric': path.join(__dirname, '../../src/renderer-lyric'),
|
||||
'@static': path.join(__dirname, '../../src/static'),
|
||||
'@common': path.join(__dirname, '../../src/common'),
|
||||
},
|
||||
extensions: ['.tsx', '.ts', '.js', '.json', '.node'],
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.js$/,
|
||||
loader: 'babel-loader',
|
||||
exclude: /node_modules/,
|
||||
},
|
||||
{
|
||||
test: /\.tsx?$/,
|
||||
exclude: /node_modules/,
|
||||
use: {
|
||||
loader: 'ts-loader',
|
||||
options: {
|
||||
appendTsSuffixTo: [/\.vue$/],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
test: /\.node$/,
|
||||
use: 'node-loader',
|
||||
},
|
||||
{
|
||||
test: /\.vue$/,
|
||||
loader: 'vue-loader',
|
||||
options: vueLoaderConfig,
|
||||
},
|
||||
{
|
||||
test: /\.pug$/,
|
||||
loader: 'pug-plain-loader',
|
||||
},
|
||||
{
|
||||
test: /\.css$/,
|
||||
oneOf: mergeCSSLoader(),
|
||||
},
|
||||
{
|
||||
test: /\.less$/,
|
||||
oneOf: mergeCSSLoader({
|
||||
loader: 'less-loader',
|
||||
options: {
|
||||
sourceMap: true,
|
||||
},
|
||||
}),
|
||||
},
|
||||
{
|
||||
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
|
||||
exclude: path.join(__dirname, '../../src/renderer/assets/svgs'),
|
||||
type: 'asset',
|
||||
parser: {
|
||||
dataUrlCondition: {
|
||||
maxSize: 10000,
|
||||
},
|
||||
},
|
||||
generator: {
|
||||
filename: 'imgs/[name]-[contenthash:8][ext]',
|
||||
},
|
||||
},
|
||||
{
|
||||
test: /\.svg$/,
|
||||
include: path.join(__dirname, '../../src/renderer/assets/svgs'),
|
||||
use: [
|
||||
{
|
||||
loader: 'svg-sprite-loader',
|
||||
options: {
|
||||
symbolId: 'icon-[name]',
|
||||
},
|
||||
},
|
||||
'svg-transform-loader',
|
||||
'svgo-loader',
|
||||
],
|
||||
},
|
||||
{
|
||||
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
|
||||
type: 'asset',
|
||||
parser: {
|
||||
dataUrlCondition: {
|
||||
maxSize: 10000,
|
||||
},
|
||||
},
|
||||
generator: {
|
||||
filename: 'media/[name]-[contenthash:8][ext]',
|
||||
},
|
||||
},
|
||||
{
|
||||
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
|
||||
type: 'asset',
|
||||
parser: {
|
||||
dataUrlCondition: {
|
||||
maxSize: 10000,
|
||||
},
|
||||
},
|
||||
generator: {
|
||||
filename: 'fonts/[name]-[contenthash:8][ext]',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
plugins: [
|
||||
new HTMLPlugin({
|
||||
filename: 'lyric.html',
|
||||
template: path.join(__dirname, '../../src/renderer-lyric/index.html'),
|
||||
isProd: process.env.NODE_ENV == 'production',
|
||||
browser: process.browser,
|
||||
__dirname,
|
||||
}),
|
||||
new VueLoaderPlugin(),
|
||||
new MiniCssExtractPlugin({
|
||||
// Options similar to the same options in webpackOptions.output
|
||||
// both options are optional
|
||||
filename: isDev ? '[name].css' : '[name].[contenthash:8].css',
|
||||
chunkFilename: isDev ? '[id].css' : '[id].[contenthash:8].css',
|
||||
}),
|
||||
new ESLintPlugin({
|
||||
extensions: ['js', 'vue'],
|
||||
formatter: require('eslint-formatter-friendly'),
|
||||
}),
|
||||
],
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
const path = require('path')
|
||||
const webpack = require('webpack')
|
||||
|
||||
const { merge } = require('webpack-merge')
|
||||
|
||||
const baseConfig = require('./webpack.config.base')
|
||||
|
||||
module.exports = merge(baseConfig, {
|
||||
mode: 'development',
|
||||
devtool: 'eval-source-map',
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
'process.env': {
|
||||
NODE_ENV: '"development"',
|
||||
ELECTRON_DISABLE_SECURITY_WARNINGS: 'true',
|
||||
},
|
||||
__VUE_OPTIONS_API__: 'true',
|
||||
__VUE_PROD_DEVTOOLS__: 'false',
|
||||
staticPath: `"${path.join(__dirname, '../../src/static').replace(/\\/g, '\\\\')}"`,
|
||||
}),
|
||||
],
|
||||
performance: {
|
||||
hints: false,
|
||||
},
|
||||
})
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
// const path = require('path')
|
||||
const webpack = require('webpack')
|
||||
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin')
|
||||
const TerserPlugin = require('terser-webpack-plugin')
|
||||
const { merge } = require('webpack-merge')
|
||||
|
||||
const baseConfig = require('./webpack.config.base')
|
||||
const buildConfig = require('../webpack-build-config')
|
||||
|
||||
// const { dependencies } = require('../../package.json')
|
||||
|
||||
// let whiteListedModules = ['vue']
|
||||
// let whiteListedModules = ['vue', 'vue-router', 'vuex', 'vue-i18n']
|
||||
|
||||
|
||||
module.exports = merge(baseConfig, {
|
||||
mode: 'production',
|
||||
devtool: false,
|
||||
externals: [
|
||||
// ...Object.keys(dependencies || {}).filter(d => !whiteListedModules.includes(d)),
|
||||
],
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
'process.env': {
|
||||
NODE_ENV: '"production"',
|
||||
},
|
||||
__VUE_OPTIONS_API__: 'true',
|
||||
__VUE_PROD_DEVTOOLS__: 'false',
|
||||
}),
|
||||
],
|
||||
optimization: {
|
||||
minimize: buildConfig.minimize,
|
||||
minimizer: [
|
||||
new TerserPlugin(),
|
||||
new CssMinimizerPlugin(),
|
||||
],
|
||||
},
|
||||
performance: {
|
||||
maxEntrypointSize: 1024 * 1024 * 10,
|
||||
maxAssetSize: 1024 * 1024 * 20,
|
||||
hints: 'warning',
|
||||
},
|
||||
node: {
|
||||
__dirname: false,
|
||||
__filename: false,
|
||||
},
|
||||
})
|
||||
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
const path = require('path')
|
||||
const ESLintPlugin = require('eslint-webpack-plugin')
|
||||
|
||||
module.exports = {
|
||||
target: 'electron-renderer',
|
||||
entry: {
|
||||
'user-api-preload': path.join(__dirname, '../../src/main/modules/userApi/renderer/preload.js'),
|
||||
},
|
||||
output: {
|
||||
filename: '[name].js',
|
||||
library: {
|
||||
type: 'commonjs2',
|
||||
},
|
||||
path: path.join(__dirname, '../../dist'),
|
||||
publicPath: '',
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
'@root': path.join(__dirname, '../../src'),
|
||||
'@main': path.join(__dirname, '../../src/main'),
|
||||
'@renderer': path.join(__dirname, '../../src/renderer'),
|
||||
'@lyric': path.join(__dirname, '../../src/renderer-lyric'),
|
||||
'@static': path.join(__dirname, '../../src/static'),
|
||||
'@common': path.join(__dirname, '../../src/common'),
|
||||
},
|
||||
extensions: ['.tsx', '.ts', '.js', '.json', '.node'],
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.js$/,
|
||||
loader: 'babel-loader',
|
||||
exclude: /node_modules/,
|
||||
},
|
||||
{
|
||||
test: /\.tsx?$/,
|
||||
exclude: /node_modules/,
|
||||
use: {
|
||||
loader: 'ts-loader',
|
||||
options: {
|
||||
appendTsSuffixTo: [/\.vue$/],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
test: /\.node$/,
|
||||
use: 'node-loader',
|
||||
},
|
||||
],
|
||||
},
|
||||
plugins: [
|
||||
new ESLintPlugin({
|
||||
extensions: ['js'],
|
||||
formatter: require('eslint-formatter-friendly'),
|
||||
}),
|
||||
],
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
const path = require('path')
|
||||
const webpack = require('webpack')
|
||||
|
||||
const { merge } = require('webpack-merge')
|
||||
|
||||
const baseConfig = require('./webpack.config.base')
|
||||
|
||||
module.exports = merge(baseConfig, {
|
||||
mode: 'development',
|
||||
devtool: 'eval-source-map',
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
'process.env': {
|
||||
NODE_ENV: '"development"',
|
||||
ELECTRON_DISABLE_SECURITY_WARNINGS: 'true',
|
||||
},
|
||||
staticPath: `"${path.join(__dirname, '../../src/static').replace(/\\/g, '\\\\')}"`,
|
||||
}),
|
||||
],
|
||||
performance: {
|
||||
hints: false,
|
||||
},
|
||||
})
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
// const path = require('path')
|
||||
const webpack = require('webpack')
|
||||
const TerserPlugin = require('terser-webpack-plugin')
|
||||
const { merge } = require('webpack-merge')
|
||||
|
||||
const baseConfig = require('./webpack.config.base')
|
||||
const buildConfig = require('../webpack-build-config')
|
||||
|
||||
// const { dependencies } = require('../../package.json')
|
||||
|
||||
// let whiteListedModules = ['vue']
|
||||
// let whiteListedModules = ['vue', 'vue-router', 'vuex', 'vue-i18n']
|
||||
|
||||
|
||||
module.exports = merge(baseConfig, {
|
||||
mode: 'production',
|
||||
devtool: false,
|
||||
externals: [
|
||||
// ...Object.keys(dependencies || {}).filter(d => !whiteListedModules.includes(d)),
|
||||
],
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
'process.env': {
|
||||
NODE_ENV: '"production"',
|
||||
},
|
||||
}),
|
||||
],
|
||||
optimization: {
|
||||
minimize: buildConfig.minimize,
|
||||
minimizer: [
|
||||
new TerserPlugin(),
|
||||
],
|
||||
},
|
||||
performance: {
|
||||
maxEntrypointSize: 1024 * 1024 * 10,
|
||||
maxAssetSize: 1024 * 1024 * 20,
|
||||
hints: 'warning',
|
||||
},
|
||||
node: {
|
||||
__dirname: false,
|
||||
__filename: false,
|
||||
},
|
||||
})
|
||||
|
||||
|
|
@ -0,0 +1,158 @@
|
|||
const path = require('path')
|
||||
const { VueLoaderPlugin } = require('vue-loader')
|
||||
const HTMLPlugin = require('html-webpack-plugin')
|
||||
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
||||
const ESLintPlugin = require('eslint-webpack-plugin')
|
||||
|
||||
const vueLoaderConfig = require('../vue-loader.config')
|
||||
const { mergeCSSLoader } = require('../utils')
|
||||
|
||||
const isDev = process.env.NODE_ENV === 'development'
|
||||
|
||||
module.exports = {
|
||||
target: 'electron-renderer',
|
||||
entry: {
|
||||
renderer: path.join(__dirname, '../../src/renderer/main.ts'),
|
||||
},
|
||||
output: {
|
||||
filename: '[name].js',
|
||||
library: {
|
||||
type: 'commonjs2',
|
||||
},
|
||||
path: path.join(__dirname, '../../dist'),
|
||||
publicPath: '',
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
'@root': path.join(__dirname, '../../src'),
|
||||
'@main': path.join(__dirname, '../../src/main'),
|
||||
'@renderer': path.join(__dirname, '../../src/renderer'),
|
||||
'@lyric': path.join(__dirname, '../../src/renderer-lyric'),
|
||||
'@static': path.join(__dirname, '../../src/static'),
|
||||
'@common': path.join(__dirname, '../../src/common'),
|
||||
},
|
||||
extensions: ['.tsx', '.ts', '.js', '.json', '.node'],
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.js$/,
|
||||
loader: 'babel-loader',
|
||||
exclude: /node_modules/,
|
||||
},
|
||||
{
|
||||
test: /\.tsx?$/,
|
||||
exclude: /node_modules/,
|
||||
use: {
|
||||
loader: 'ts-loader',
|
||||
options: {
|
||||
appendTsSuffixTo: [/\.vue$/],
|
||||
},
|
||||
},
|
||||
parser: {
|
||||
worker: [
|
||||
'*audioContext.audioWorklet.addModule()',
|
||||
'...',
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
test: /\.node$/,
|
||||
use: 'node-loader',
|
||||
},
|
||||
{
|
||||
test: /\.vue$/,
|
||||
loader: 'vue-loader',
|
||||
options: vueLoaderConfig,
|
||||
},
|
||||
{
|
||||
test: /\.pug$/,
|
||||
loader: 'pug-plain-loader',
|
||||
},
|
||||
{
|
||||
test: /\.css$/,
|
||||
oneOf: mergeCSSLoader(),
|
||||
},
|
||||
{
|
||||
test: /\.less$/,
|
||||
oneOf: mergeCSSLoader({
|
||||
loader: 'less-loader',
|
||||
options: {
|
||||
sourceMap: true,
|
||||
},
|
||||
}),
|
||||
},
|
||||
{
|
||||
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
|
||||
exclude: path.join(__dirname, '../../src/renderer/assets/svgs'),
|
||||
type: 'asset',
|
||||
parser: {
|
||||
dataUrlCondition: {
|
||||
maxSize: 10000,
|
||||
},
|
||||
},
|
||||
generator: {
|
||||
filename: 'imgs/[name]-[contenthash:8][ext]',
|
||||
},
|
||||
},
|
||||
{
|
||||
test: /\.svg$/,
|
||||
include: path.join(__dirname, '../../src/renderer/assets/svgs'),
|
||||
use: [
|
||||
{
|
||||
loader: 'svg-sprite-loader',
|
||||
options: {
|
||||
symbolId: 'icon-[name]',
|
||||
},
|
||||
},
|
||||
'svg-transform-loader',
|
||||
'svgo-loader',
|
||||
],
|
||||
},
|
||||
{
|
||||
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)$/,
|
||||
type: 'asset',
|
||||
parser: {
|
||||
dataUrlCondition: {
|
||||
maxSize: 10000,
|
||||
},
|
||||
},
|
||||
generator: {
|
||||
filename: 'media/[name]-[contenthash:8][ext]',
|
||||
},
|
||||
},
|
||||
{
|
||||
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
|
||||
type: 'asset',
|
||||
parser: {
|
||||
dataUrlCondition: {
|
||||
maxSize: 10000,
|
||||
},
|
||||
},
|
||||
generator: {
|
||||
filename: 'fonts/[name]-[contenthash:8][ext]',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
plugins: [
|
||||
new HTMLPlugin({
|
||||
filename: 'index.html',
|
||||
template: path.join(__dirname, '../../src/renderer/index.html'),
|
||||
isProd: process.env.NODE_ENV == 'production',
|
||||
browser: process.browser,
|
||||
__dirname,
|
||||
}),
|
||||
new VueLoaderPlugin(),
|
||||
new MiniCssExtractPlugin({
|
||||
// Options similar to the same options in webpackOptions.output
|
||||
// both options are optional
|
||||
filename: isDev ? '[name].css' : '[name].[contenthash:8].css',
|
||||
chunkFilename: isDev ? '[id].css' : '[id].[contenthash:8].css',
|
||||
}),
|
||||
new ESLintPlugin({
|
||||
extensions: ['js', 'vue'],
|
||||
formatter: require('eslint-formatter-friendly'),
|
||||
}),
|
||||
],
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
const path = require('path')
|
||||
const webpack = require('webpack')
|
||||
|
||||
const { merge } = require('webpack-merge')
|
||||
|
||||
const baseConfig = require('./webpack.config.base')
|
||||
|
||||
module.exports = merge(baseConfig, {
|
||||
mode: 'development',
|
||||
devtool: 'eval-source-map',
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
'process.env': {
|
||||
NODE_ENV: '"development"',
|
||||
ELECTRON_DISABLE_SECURITY_WARNINGS: 'true',
|
||||
},
|
||||
// ENVIRONMENT: 'process.env',
|
||||
__VUE_OPTIONS_API__: 'true',
|
||||
__VUE_PROD_DEVTOOLS__: 'false',
|
||||
staticPath: `"${path.join(__dirname, '../../src/static').replace(/\\/g, '\\\\')}"`,
|
||||
}),
|
||||
],
|
||||
performance: {
|
||||
hints: false,
|
||||
},
|
||||
})
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
const path = require('path')
|
||||
const webpack = require('webpack')
|
||||
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin')
|
||||
const TerserPlugin = require('terser-webpack-plugin')
|
||||
const CopyWebpackPlugin = require('copy-webpack-plugin')
|
||||
const { merge } = require('webpack-merge')
|
||||
|
||||
const baseConfig = require('./webpack.config.base')
|
||||
const buildConfig = require('../webpack-build-config')
|
||||
|
||||
// const { dependencies } = require('../../package.json')
|
||||
|
||||
// let whiteListedModules = ['vue', 'vue-router', 'vuex', 'vue-i18n']
|
||||
|
||||
|
||||
module.exports = merge(baseConfig, {
|
||||
mode: 'production',
|
||||
devtool: false,
|
||||
externals: [
|
||||
// ...Object.keys(dependencies || {}).filter(d => !whiteListedModules.includes(d)),
|
||||
],
|
||||
plugins: [
|
||||
new CopyWebpackPlugin({
|
||||
patterns: [
|
||||
{
|
||||
from: path.join(__dirname, '../../src/static'),
|
||||
to: path.join(__dirname, '../../dist/static'),
|
||||
},
|
||||
],
|
||||
}),
|
||||
new webpack.DefinePlugin({
|
||||
'process.env': {
|
||||
NODE_ENV: '"production"',
|
||||
},
|
||||
// ENVIRONMENT: 'process.env',
|
||||
__VUE_OPTIONS_API__: 'true',
|
||||
__VUE_PROD_DEVTOOLS__: 'false',
|
||||
}),
|
||||
],
|
||||
optimization: {
|
||||
minimize: buildConfig.minimize,
|
||||
minimizer: [
|
||||
new TerserPlugin(),
|
||||
new CssMinimizerPlugin(),
|
||||
],
|
||||
splitChunks: {
|
||||
chunks: 'initial',
|
||||
minChunks: 2,
|
||||
},
|
||||
},
|
||||
performance: {
|
||||
maxEntrypointSize: 1024 * 1024 * 10,
|
||||
maxAssetSize: 1024 * 1024 * 20,
|
||||
hints: 'warning',
|
||||
},
|
||||
node: {
|
||||
__dirname: false,
|
||||
__filename: false,
|
||||
},
|
||||
})
|
||||
|
||||
|
|
@ -1,3 +1,250 @@
|
|||
process.env.NODE_ENV = 'development'
|
||||
|
||||
require('./vite/runner-dev')
|
||||
const chalk = require('chalk')
|
||||
const electron = require('electron')
|
||||
const path = require('path')
|
||||
// const { say } = require('cfonts')
|
||||
const { spawn } = require('child_process')
|
||||
const webpack = require('webpack')
|
||||
const WebpackDevServer = require('webpack-dev-server')
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin')
|
||||
const webpackHotMiddleware = require('webpack-hot-middleware')
|
||||
|
||||
const mainConfig = require('./main/webpack.config.dev')
|
||||
const rendererConfig = require('./renderer/webpack.config.dev')
|
||||
const rendererLyricConfig = require('./renderer-lyric/webpack.config.dev')
|
||||
const rendererScriptConfig = require('./renderer-scripts/webpack.config.dev')
|
||||
const { Arch } = require('electron-builder')
|
||||
const replaceLib = require('./build-before-pack')
|
||||
|
||||
let electronProcess = null
|
||||
let manualRestart = false
|
||||
let hotMiddlewareRenderer
|
||||
let hotMiddlewareRendererLyric
|
||||
|
||||
|
||||
function startRenderer() {
|
||||
return new Promise((resolve, reject) => {
|
||||
// rendererConfig.entry.renderer = [path.join(__dirname, 'dev-client')].concat(rendererConfig.entry.renderer)
|
||||
// rendererConfig.mode = 'development'
|
||||
const compiler = webpack(rendererConfig)
|
||||
hotMiddlewareRenderer = webpackHotMiddleware(compiler, {
|
||||
log: false,
|
||||
heartbeat: 2500,
|
||||
})
|
||||
|
||||
compiler.hooks.compilation.tap('compilation', compilation => {
|
||||
// console.log(Object.keys(compilation.hooks))
|
||||
HtmlWebpackPlugin.getHooks(compilation).beforeEmit.tapAsync('html-webpack-plugin-after-emit', (data, cb) => {
|
||||
hotMiddlewareRenderer.publish({ action: 'reload' })
|
||||
cb()
|
||||
})
|
||||
})
|
||||
|
||||
// compiler.hooks.done.tap('done', stats => {
|
||||
// // logStats('Renderer', 'Compile done')
|
||||
// // logStats('Renderer', stats)
|
||||
// })
|
||||
|
||||
const server = new WebpackDevServer({
|
||||
port: 9080,
|
||||
hot: true,
|
||||
historyApiFallback: true,
|
||||
static: {
|
||||
directory: path.join(__dirname, '../src/common/theme/images'),
|
||||
publicPath: '/theme_images',
|
||||
},
|
||||
client: {
|
||||
logging: 'warn',
|
||||
overlay: true,
|
||||
},
|
||||
setupMiddlewares(middlewares, devServer) {
|
||||
devServer.app.use(hotMiddlewareRenderer)
|
||||
devServer.middleware.waitUntilValid(resolve)
|
||||
|
||||
return middlewares
|
||||
},
|
||||
}, compiler)
|
||||
|
||||
server.start()
|
||||
})
|
||||
}
|
||||
|
||||
function startRendererLyric() {
|
||||
return new Promise((resolve, reject) => {
|
||||
// rendererConfig.entry.renderer = [path.join(__dirname, 'dev-client')].concat(rendererConfig.entry.renderer)
|
||||
// rendererConfig.mode = 'development'
|
||||
const compiler = webpack(rendererLyricConfig)
|
||||
hotMiddlewareRendererLyric = webpackHotMiddleware(compiler, {
|
||||
log: false,
|
||||
heartbeat: 2500,
|
||||
})
|
||||
|
||||
compiler.hooks.compilation.tap('compilation', compilation => {
|
||||
// console.log(Object.keys(compilation.hooks))
|
||||
HtmlWebpackPlugin.getHooks(compilation).beforeEmit.tapAsync('html-webpack-plugin-after-emit', (data, cb) => {
|
||||
hotMiddlewareRendererLyric.publish({ action: 'reload' })
|
||||
cb()
|
||||
})
|
||||
})
|
||||
|
||||
// compiler.hooks.done.tap('done', stats => {
|
||||
// // logStats('Renderer', 'Compile done')
|
||||
// // logStats('Renderer', stats)
|
||||
// })
|
||||
|
||||
const server = new WebpackDevServer({
|
||||
port: 9081,
|
||||
hot: true,
|
||||
historyApiFallback: true,
|
||||
// static: {
|
||||
// directory: path.join(__dirname, '../'),
|
||||
// },
|
||||
client: {
|
||||
logging: 'warn',
|
||||
overlay: true,
|
||||
},
|
||||
setupMiddlewares(middlewares, devServer) {
|
||||
devServer.app.use(hotMiddlewareRenderer)
|
||||
devServer.middleware.waitUntilValid(resolve)
|
||||
return middlewares
|
||||
},
|
||||
}, compiler)
|
||||
|
||||
server.start()
|
||||
})
|
||||
}
|
||||
|
||||
function startRendererScripts() {
|
||||
return new Promise((resolve, reject) => {
|
||||
// mainConfig.entry.main = [path.join(__dirname, '../src/main/index.dev.js')].concat(mainConfig.entry.main)
|
||||
// mainConfig.mode = 'development'
|
||||
const compiler = webpack(rendererScriptConfig)
|
||||
|
||||
compiler.watch({}, (err, stats) => {
|
||||
if (err) {
|
||||
console.log(err)
|
||||
return
|
||||
}
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function startMain() {
|
||||
return new Promise((resolve, reject) => {
|
||||
// mainConfig.entry.main = [path.join(__dirname, '../src/main/index.dev.js')].concat(mainConfig.entry.main)
|
||||
// mainConfig.mode = 'development'
|
||||
const compiler = webpack(mainConfig)
|
||||
|
||||
compiler.hooks.watchRun.tapAsync('watch-run', (compilation, done) => {
|
||||
hotMiddlewareRenderer.publish({ action: 'compiling' })
|
||||
hotMiddlewareRendererLyric.publish({ action: 'compiling' })
|
||||
done()
|
||||
})
|
||||
|
||||
compiler.watch({}, (err, stats) => {
|
||||
if (err) {
|
||||
console.log(err)
|
||||
return
|
||||
}
|
||||
|
||||
// logStats('Main', stats)
|
||||
|
||||
if (electronProcess && electronProcess.kill) {
|
||||
manualRestart = true
|
||||
process.kill(electronProcess.pid)
|
||||
electronProcess = null
|
||||
startElectron()
|
||||
|
||||
setTimeout(() => {
|
||||
manualRestart = false
|
||||
}, 5000)
|
||||
}
|
||||
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function startElectron() {
|
||||
let args = [
|
||||
'--inspect=5858',
|
||||
// 'NODE_ENV=development',
|
||||
path.join(__dirname, '../dist/main.js'),
|
||||
]
|
||||
|
||||
// detect yarn or npm and process commandline args accordingly
|
||||
if (process.env.npm_execpath.endsWith('yarn.js')) {
|
||||
args = args.concat(process.argv.slice(3))
|
||||
} else if (process.env.npm_execpath.endsWith('npm-cli.js')) {
|
||||
args = args.concat(process.argv.slice(2))
|
||||
}
|
||||
|
||||
electronProcess = spawn(electron, args)
|
||||
|
||||
electronProcess.stdout.on('data', data => {
|
||||
electronLog(data, 'blue')
|
||||
})
|
||||
electronProcess.stderr.on('data', data => {
|
||||
electronLog(data, 'red')
|
||||
})
|
||||
|
||||
electronProcess.on('close', () => {
|
||||
if (!manualRestart) process.exit()
|
||||
})
|
||||
}
|
||||
|
||||
const logs = [
|
||||
'Manifest version 2 is deprecated, and support will be removed in 2023',
|
||||
'"Extension server error: Operation failed: Permission denied", source: devtools://devtools/bundled',
|
||||
|
||||
// https://github.com/electron/electron/issues/32133
|
||||
'"Electron sandbox_bundle.js script failed to run"',
|
||||
'"TypeError: object null is not iterable (cannot read property Symbol(Symbol.iterator))",',
|
||||
]
|
||||
function electronLog(data, color) {
|
||||
let log = data.toString()
|
||||
if (/[0-9A-z]+/.test(log)) {
|
||||
// 抑制某些无关的报错日志
|
||||
if (color == 'red' && typeof log === 'string' && logs.some(l => log.includes(l))) return
|
||||
|
||||
console.log(chalk[color](log))
|
||||
}
|
||||
}
|
||||
|
||||
function init() {
|
||||
const Spinnies = require('spinnies')
|
||||
const spinners = new Spinnies({ color: 'blue' })
|
||||
spinners.add('main', { text: 'main compiling' })
|
||||
spinners.add('renderer', { text: 'renderer compiling' })
|
||||
spinners.add('renderer-lyric', { text: 'renderer-lyric compiling' })
|
||||
spinners.add('renderer-scripts', { text: 'renderer-scripts compiling' })
|
||||
function handleSuccess(name) {
|
||||
spinners.succeed(name, { text: name + ' compile success!' })
|
||||
}
|
||||
function handleFail(name) {
|
||||
spinners.fail(name, { text: name + ' compile fail!' })
|
||||
}
|
||||
replaceLib({ electronPlatformName: process.platform, arch: Arch[process.arch] })
|
||||
|
||||
Promise.all([
|
||||
startRenderer().then(() => handleSuccess('renderer')).catch((err) => {
|
||||
console.error(err.message)
|
||||
return handleFail('renderer')
|
||||
}),
|
||||
startRendererLyric().then(() => handleSuccess('renderer-lyric')).catch((err) => {
|
||||
console.error(err.message)
|
||||
return handleFail('renderer-lyric')
|
||||
}),
|
||||
startRendererScripts().then(() => handleSuccess('renderer-scripts')).catch((err) => {
|
||||
console.error(err.message)
|
||||
return handleFail('renderer-scripts')
|
||||
}),
|
||||
startMain().then(() => handleSuccess('main')).catch(() => handleFail('main')),
|
||||
]).then(startElectron).catch(err => {
|
||||
console.error(err)
|
||||
})
|
||||
}
|
||||
|
||||
init()
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
||||
const cssLoaderConfig = require('./css-loader.config')
|
||||
const chalk = require('chalk')
|
||||
|
||||
// merge css-loader
|
||||
exports.mergeCSSLoader = beforeLoader => {
|
||||
const loader = [
|
||||
// 这里匹配 `<style module>`
|
||||
{
|
||||
resourceQuery: /module/,
|
||||
use: [
|
||||
{
|
||||
loader: MiniCssExtractPlugin.loader,
|
||||
options: {
|
||||
esModule: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
loader: 'css-loader',
|
||||
options: cssLoaderConfig,
|
||||
},
|
||||
'postcss-loader',
|
||||
],
|
||||
},
|
||||
// 这里匹配普通的 `<style>` 或 `<style scoped>`
|
||||
{
|
||||
use: [
|
||||
{
|
||||
loader: MiniCssExtractPlugin.loader,
|
||||
options: {
|
||||
esModule: false,
|
||||
},
|
||||
},
|
||||
'css-loader',
|
||||
'postcss-loader',
|
||||
],
|
||||
},
|
||||
]
|
||||
if (beforeLoader) {
|
||||
loader[0].use.push(beforeLoader)
|
||||
loader[1].use.push(beforeLoader)
|
||||
}
|
||||
return loader
|
||||
}
|
||||
|
||||
exports.logStats = (proc, data) => {
|
||||
let log = ''
|
||||
|
||||
log += chalk.yellow.bold(`${proc} Process:`)
|
||||
log += '\n'
|
||||
|
||||
if (typeof data === 'object') {
|
||||
data.toString({
|
||||
colors: true,
|
||||
chunks: false,
|
||||
}).split(/\r?\n/).forEach(line => {
|
||||
log += ' ' + line + '\n'
|
||||
})
|
||||
} else {
|
||||
log += ` ${data}\n`
|
||||
}
|
||||
|
||||
console.log(log)
|
||||
}
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
import path from 'node:path'
|
||||
import type { UserConfig } from 'vite'
|
||||
import { builtinModules } from 'node:module'
|
||||
|
||||
const isProd = process.env.NODE_ENV == 'production'
|
||||
|
||||
const rootPath = path.join(__dirname, '../../../')
|
||||
|
||||
|
||||
const config: UserConfig = {
|
||||
mode: process.env.NODE_ENV == 'production' ? 'production' : 'development',
|
||||
root: path.join(rootPath, 'src/main'),
|
||||
base: './',
|
||||
publicDir: false,
|
||||
logLevel: 'warn',
|
||||
resolve: {
|
||||
alias: {
|
||||
'@root': path.join(rootPath, 'src'),
|
||||
'@common': path.join(rootPath, 'src/common'),
|
||||
'@static': path.join(__dirname, 'src/static'),
|
||||
'@main': path.join(rootPath, 'src/main'),
|
||||
},
|
||||
browserField: false,
|
||||
},
|
||||
build: {
|
||||
lib: {
|
||||
entry: `${isProd ? 'index.ts' : 'index-dev.ts'}`,
|
||||
formats: ['cjs'],
|
||||
fileName: 'main',
|
||||
},
|
||||
outDir: path.join(rootPath, 'dist/main'),
|
||||
emptyOutDir: true,
|
||||
reportCompressedSize: false,
|
||||
modulePreload: false,
|
||||
// assetsDir: 'chunks',
|
||||
minify: false,
|
||||
watch: {
|
||||
buildDelay: 500,
|
||||
},
|
||||
commonjsOptions: {
|
||||
dynamicRequireTargets: ['*.js'],
|
||||
ignoreDynamicRequires: true,
|
||||
},
|
||||
rollupOptions: {
|
||||
external: [
|
||||
'electron',
|
||||
'better-sqlite3',
|
||||
'font-list',
|
||||
'electron-font-manager',
|
||||
...builtinModules.flatMap(m => [m, `node:${m}`]),
|
||||
],
|
||||
input: {
|
||||
main: `src/main/${isProd ? 'index.ts' : 'index-dev.ts'}`,
|
||||
'dbService.worker': 'src/main/worker/dbService/index.ts',
|
||||
},
|
||||
output: {
|
||||
entryFileNames: '[name].js',
|
||||
chunkFileNames: '[name].js',
|
||||
format: 'cjs',
|
||||
// manualChunks(id, info) {
|
||||
// // return 'main'
|
||||
// },
|
||||
experimentalMinChunkSize: 50_000,
|
||||
},
|
||||
logLevel: 'warn',
|
||||
},
|
||||
},
|
||||
define: {
|
||||
'process.env.NODE_ENV': `"${process.env.NODE_ENV as string}"`,
|
||||
__STATIC_PATH__: `"${path.join(rootPath, 'src/static').replace(/\\/g, '\\\\')}"`,
|
||||
__USER_API_PATH__: `"${path.join(rootPath, 'src/main/modules/userApi').replace(/\\/g, '\\\\')}"`,
|
||||
__QRC_DECODE_NODE_PATH__: `"${(isProd ? '../../build/Release' : path.join(rootPath, 'build/Release')).replace(/\\/g, '\\\\')}"`,
|
||||
},
|
||||
cacheDir: path.join(rootPath, 'node_modules/.vite/main'),
|
||||
}
|
||||
|
||||
export default config
|
|
@ -1,74 +0,0 @@
|
|||
import path from 'node:path'
|
||||
import type { UserConfig } from 'vite'
|
||||
import { builtinModules } from 'node:module'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import renderer from 'vite-plugin-electron-renderer'
|
||||
import postcssConfig from './postcss.config'
|
||||
|
||||
// const isProd = process.env.NODE_ENV == 'production'
|
||||
const rootPath = path.join(__dirname, '../../../')
|
||||
|
||||
const external = ['electron', ...builtinModules.flatMap(m => [m, `node:${m}`])]
|
||||
|
||||
const config: UserConfig = {
|
||||
mode: process.env.NODE_ENV == 'production' ? 'production' : 'development',
|
||||
root: path.join(rootPath, 'src/renderer-lyric'),
|
||||
base: './',
|
||||
publicDir: false,
|
||||
logLevel: 'warn',
|
||||
resolve: {
|
||||
alias: {
|
||||
'@root': path.join(rootPath, 'src'),
|
||||
'@common': path.join(rootPath, 'src/common'),
|
||||
'@static': path.join(__dirname, 'src/static'),
|
||||
'@lyric': path.join(rootPath, 'src/renderer-lyric'),
|
||||
},
|
||||
browserField: true,
|
||||
},
|
||||
plugins: [vue(), renderer()],
|
||||
build: {
|
||||
target: 'esnext',
|
||||
outDir: path.join(rootPath, 'dist/renderer-lyric'),
|
||||
modulePreload: false,
|
||||
emptyOutDir: true,
|
||||
reportCompressedSize: false,
|
||||
assetsDir: './',
|
||||
// assetsDir: 'chunks',
|
||||
minify: false,
|
||||
watch: {
|
||||
buildDelay: 500,
|
||||
},
|
||||
rollupOptions: {
|
||||
external,
|
||||
input: {
|
||||
'renderer-lyric': 'src/renderer-lyric/index.html',
|
||||
},
|
||||
output: {
|
||||
entryFileNames: '[name].js',
|
||||
format: 'cjs',
|
||||
// manualChunks(id, info) {
|
||||
// return 'renderer'
|
||||
// },
|
||||
experimentalMinChunkSize: 50_000,
|
||||
},
|
||||
logLevel: 'warn',
|
||||
},
|
||||
},
|
||||
css: {
|
||||
postcss: postcssConfig,
|
||||
},
|
||||
optimizeDeps: {
|
||||
include: [],
|
||||
},
|
||||
define: {
|
||||
'process.env.NODE_ENV': `"${process.env.NODE_ENV as string}"`,
|
||||
'process.env.ELECTRON_DISABLE_SECURITY_WARNINGS': 'true',
|
||||
__STATIC_PATH__: `"${path.join(rootPath, 'src/static').replace(/\\/g, '\\\\')}"`,
|
||||
},
|
||||
server: {
|
||||
port: 9081,
|
||||
},
|
||||
cacheDir: path.join(rootPath, 'node_modules/.vite/renderer-lyric'),
|
||||
}
|
||||
|
||||
export default config
|
|
@ -1,61 +0,0 @@
|
|||
import path from 'node:path'
|
||||
import type { UserConfig } from 'vite'
|
||||
import { builtinModules } from 'node:module'
|
||||
|
||||
// const isProd = process.env.NODE_ENV == 'production'
|
||||
const rootPath = path.join(__dirname, '../../../')
|
||||
|
||||
const config: UserConfig = {
|
||||
mode: process.env.NODE_ENV,
|
||||
root: path.join(rootPath, 'src/main'),
|
||||
base: './',
|
||||
publicDir: false,
|
||||
logLevel: 'warn',
|
||||
resolve: {
|
||||
alias: {
|
||||
'@root': path.join(rootPath, 'src'),
|
||||
'@common': path.join(rootPath, 'src/common'),
|
||||
'@static': path.join(__dirname, 'src/static'),
|
||||
},
|
||||
browserField: true,
|
||||
},
|
||||
build: {
|
||||
lib: {
|
||||
entry: 'modules/userApi/renderer/preload.js',
|
||||
formats: ['cjs'],
|
||||
fileName: 'user-api-preload',
|
||||
},
|
||||
outDir: path.join(rootPath, 'dist/preload'),
|
||||
modulePreload: {
|
||||
polyfill: false,
|
||||
},
|
||||
emptyOutDir: true,
|
||||
reportCompressedSize: false,
|
||||
// assetsDir: 'chunks',
|
||||
minify: false,
|
||||
watch: {
|
||||
buildDelay: 500,
|
||||
},
|
||||
rollupOptions: {
|
||||
external: ['electron', ...builtinModules.flatMap(m => [m, `node:${m}`])],
|
||||
input: {
|
||||
'user-api-preload': 'src/main/modules/userApi/renderer/preload.js',
|
||||
},
|
||||
output: {
|
||||
entryFileNames: '[name].js',
|
||||
// manualChunks(id, info) {
|
||||
// // return 'main'
|
||||
// },
|
||||
experimentalMinChunkSize: 50_000,
|
||||
},
|
||||
logLevel: 'warn',
|
||||
},
|
||||
},
|
||||
define: {
|
||||
'process.env.NODE_ENV': `"${process.env.NODE_ENV as string}"`,
|
||||
__STATIC_PATH__: `"${path.join(rootPath, 'src/static').replace(/\\/g, '\\\\')}"`,
|
||||
},
|
||||
cacheDir: path.join(rootPath, 'node_modules/.vite/scripts'),
|
||||
}
|
||||
|
||||
export default config
|
|
@ -1,105 +0,0 @@
|
|||
import path from 'node:path'
|
||||
import type { UserConfig } from 'vite'
|
||||
import { builtinModules } from 'node:module'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import renderer from 'vite-plugin-electron-renderer'
|
||||
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
|
||||
import postcssConfig from './postcss.config'
|
||||
|
||||
const isProd = process.env.NODE_ENV == 'production'
|
||||
const rootPath = path.join(__dirname, '../../../')
|
||||
|
||||
const external = ['electron', ...builtinModules.flatMap(m => [m, `node:${m}`])]
|
||||
|
||||
const config: UserConfig = {
|
||||
mode: process.env.NODE_ENV == 'production' ? 'production' : 'development',
|
||||
root: path.join(rootPath, 'src/renderer'),
|
||||
base: './',
|
||||
publicDir: isProd ? false : path.join(rootPath, 'src/common/theme'),
|
||||
logLevel: 'warn',
|
||||
resolve: {
|
||||
alias: {
|
||||
'@root': path.join(rootPath, 'src'),
|
||||
'@common': path.join(rootPath, 'src/common'),
|
||||
'@static': path.join(__dirname, 'src/static'),
|
||||
'@renderer': path.join(rootPath, 'src/renderer'),
|
||||
},
|
||||
browserField: true,
|
||||
},
|
||||
plugins: [
|
||||
vue(),
|
||||
renderer(),
|
||||
createSvgIconsPlugin({
|
||||
iconDirs: [path.join(rootPath, 'src/renderer/assets/svgs')],
|
||||
}),
|
||||
],
|
||||
build: {
|
||||
target: 'esnext',
|
||||
outDir: path.join(rootPath, 'dist/renderer'),
|
||||
modulePreload: false,
|
||||
emptyOutDir: true,
|
||||
reportCompressedSize: false,
|
||||
// assetsDir: 'chunks',
|
||||
assetsDir: './',
|
||||
minify: false,
|
||||
watch: {
|
||||
buildDelay: 500,
|
||||
},
|
||||
rollupOptions: {
|
||||
external,
|
||||
input: {
|
||||
renderer: 'src/renderer/index.html',
|
||||
},
|
||||
output: {
|
||||
entryFileNames: '[name].js',
|
||||
format: 'cjs',
|
||||
experimentalMinChunkSize: 50_000,
|
||||
// manualChunks: {
|
||||
// 'iconv-lite': ['iconv-lite'],
|
||||
// },
|
||||
},
|
||||
logLevel: 'warn',
|
||||
},
|
||||
commonjsOptions: {
|
||||
include: [
|
||||
/vendors/,
|
||||
/node_modules/,
|
||||
/utils\/musicMeta/,
|
||||
],
|
||||
},
|
||||
},
|
||||
css: {
|
||||
postcss: postcssConfig,
|
||||
},
|
||||
optimizeDeps: {
|
||||
// // exclude: [],
|
||||
include: [
|
||||
'@common/utils/musicMeta',
|
||||
'@renderer/utils/musicSdk/kg/vendors/infSign.min',
|
||||
],
|
||||
},
|
||||
define: {
|
||||
'process.env.NODE_ENV': `"${process.env.NODE_ENV as string}"`,
|
||||
'process.env.ELECTRON_DISABLE_SECURITY_WARNINGS': 'true',
|
||||
__STATIC_PATH__: `"${path.join(rootPath, 'src/static').replace(/\\/g, '\\\\')}"`,
|
||||
},
|
||||
server: {
|
||||
port: 9080,
|
||||
},
|
||||
worker: {
|
||||
plugins: [renderer()],
|
||||
rollupOptions: {
|
||||
output: {
|
||||
// entryFileNames: '[name].js',
|
||||
inlineDynamicImports: true,
|
||||
format: 'iife',
|
||||
experimentalMinChunkSize: 50_000,
|
||||
},
|
||||
logLevel: 'warn',
|
||||
},
|
||||
// format: 'es',
|
||||
},
|
||||
cacheDir: path.join(rootPath, 'node_modules/.vite/renderer'),
|
||||
}
|
||||
|
||||
export default config
|
|
@ -1,27 +0,0 @@
|
|||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
|
||||
const rootPath = path.join(__dirname, '../../')
|
||||
|
||||
const assets = [
|
||||
[
|
||||
path.join(rootPath, './src/main/modules/userApi/renderer/user-api.html'),
|
||||
path.join(rootPath, './dist/main/user-api.html'),
|
||||
],
|
||||
[
|
||||
path.join(rootPath, './src/static'),
|
||||
path.join(rootPath, './dist/static'),
|
||||
],
|
||||
[
|
||||
path.join(rootPath, './src/common/theme/theme_images'),
|
||||
path.join(rootPath, './dist/renderer/theme_images'),
|
||||
],
|
||||
] as const
|
||||
|
||||
export default async() => {
|
||||
for (const [from, to] of assets) {
|
||||
await fs.promises.cp(from, to, {
|
||||
recursive: true,
|
||||
})
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
|
||||
import del from 'del'
|
||||
import Spinnies from 'spinnies'
|
||||
import { createLogger } from 'vite'
|
||||
import colors from 'picocolors'
|
||||
import { runBuildWorker, type TaksName } from './utils'
|
||||
// import rendererConfig from './configs/renderer'
|
||||
import copyAssets from './copyAssets'
|
||||
|
||||
const logger = createLogger('info')
|
||||
|
||||
const runMainThread = async() => {
|
||||
console.time('Build time')
|
||||
del.sync(['dist/**', 'build/**', 'node_modules/.vite/**'])
|
||||
|
||||
const noop = () => {}
|
||||
|
||||
|
||||
const spinners = new Spinnies({ color: 'blue' })
|
||||
spinners.add('renderer', { text: 'renderer compiling' })
|
||||
spinners.add('renderer-lyric', { text: 'renderer-lyric compiling' })
|
||||
spinners.add('renderer-scripts', { text: 'renderer-scripts compiling' })
|
||||
spinners.add('main', { text: 'main compiling' })
|
||||
const handleResult = (name: TaksName) => {
|
||||
return (success: boolean) => {
|
||||
if (success) {
|
||||
spinners.succeed(name, { text: name + ' compile success!' })
|
||||
} else {
|
||||
spinners.fail(name, { text: name + ' compile fail!' })
|
||||
}
|
||||
return success
|
||||
}
|
||||
}
|
||||
|
||||
const buildTasks = [
|
||||
runBuildWorker('renderer', noop).then(handleResult('renderer')),
|
||||
runBuildWorker('renderer-lyric', noop).then(handleResult('renderer-lyric')),
|
||||
runBuildWorker('renderer-scripts', noop).then(handleResult('renderer-scripts')),
|
||||
runBuildWorker('main', noop).then(handleResult('main')),
|
||||
// build(rendererConfig, noop).then(handleResult('renderer')),
|
||||
]
|
||||
|
||||
if (!await Promise.all(buildTasks).then((result) => result.every(s => s))) {
|
||||
console.timeEnd('Build time')
|
||||
throw new Error('Build failed')
|
||||
}
|
||||
|
||||
await copyAssets()
|
||||
|
||||
// listr.run().then(() => {
|
||||
|
||||
logger.info(colors.green('\nAll task build successfully'))
|
||||
// })
|
||||
console.timeEnd('Build time')
|
||||
}
|
||||
|
||||
void runMainThread().then(() => {
|
||||
process.exit(0)
|
||||
}).catch(err => {
|
||||
console.log(err)
|
||||
throw err
|
||||
})
|
|
@ -1,119 +0,0 @@
|
|||
import { type ChildProcessWithoutNullStreams, spawn } from 'node:child_process'
|
||||
import path from 'node:path'
|
||||
import colors from 'picocolors'
|
||||
import del from 'del'
|
||||
import electron from 'electron'
|
||||
import { createLogger } from 'vite'
|
||||
import { type TaksName, build, runBuildWorker } from './utils'
|
||||
import Spinnies from 'spinnies'
|
||||
import replaceLib from '../build-before-pack'
|
||||
import { Arch } from 'electron-builder'
|
||||
import mainConfig from './configs/main'
|
||||
|
||||
const logger = createLogger('info')
|
||||
|
||||
del.sync(['dist/**', 'node_modules/.vite/**'])
|
||||
|
||||
const logs = [
|
||||
'Manifest version 2 is deprecated, and support will be removed in 2023',
|
||||
'"Extension server error: Operation failed: Permission denied", source: devtools://devtools/bundled',
|
||||
|
||||
// https://github.com/electron/electron/issues/32133
|
||||
'"Electron sandbox_bundle.js script failed to run"',
|
||||
'"TypeError: object null is not iterable (cannot read property Symbol(Symbol.iterator))",',
|
||||
]
|
||||
function electronLog(data: Buffer, color: 'red' | 'blue') {
|
||||
let log = data.toString()
|
||||
if (/[0-9A-z]+/.test(log)) {
|
||||
// 抑制某些无关的报错日志
|
||||
if (color == 'red' && typeof log === 'string' && logs.some(l => log.includes(l))) return
|
||||
|
||||
logger.info(colors[color](log))
|
||||
}
|
||||
}
|
||||
export const runElectron = () => {
|
||||
let args = [
|
||||
'--inspect=5858',
|
||||
// 'NODE_ENV=development',
|
||||
path.join(__dirname, '../../dist/main/main.js'),
|
||||
]
|
||||
|
||||
// detect yarn or npm and process commandline args accordingly
|
||||
if (process.env.npm_execpath?.endsWith('yarn.js')) {
|
||||
args = args.concat(process.argv.slice(3))
|
||||
} else if (process.env.npm_execpath?.endsWith('npm-cli.js')) {
|
||||
args = args.concat(process.argv.slice(2))
|
||||
}
|
||||
|
||||
const electronProcess = spawn(electron as unknown as string, args)
|
||||
|
||||
electronProcess.stdout.on('data', data => {
|
||||
electronLog(data, 'blue')
|
||||
})
|
||||
electronProcess.stderr.on('data', data => {
|
||||
electronLog(data, 'red')
|
||||
})
|
||||
|
||||
electronProcess.on('close', () => {
|
||||
process.exit()
|
||||
})
|
||||
|
||||
return electronProcess
|
||||
}
|
||||
|
||||
const runMainThread = async() => {
|
||||
console.time('init')
|
||||
|
||||
// let server: ViteDevServer | undefined
|
||||
let electronProcess: ChildProcessWithoutNullStreams | undefined
|
||||
|
||||
const noop = () => {}
|
||||
const handleUpdate = () => {
|
||||
logger.info(colors.green('\nrebuild the electron main process successfully'))
|
||||
|
||||
if (electronProcess) {
|
||||
electronProcess.removeAllListeners()
|
||||
electronProcess.kill()
|
||||
}
|
||||
|
||||
electronProcess = runElectron()
|
||||
logger.info(colors.green('\nrestart electron app...'))
|
||||
}
|
||||
|
||||
const spinners = new Spinnies({ color: 'blue' })
|
||||
spinners.add('renderer', { text: 'renderer compiling' })
|
||||
spinners.add('renderer-lyric', { text: 'renderer-lyric compiling' })
|
||||
spinners.add('renderer-scripts', { text: 'renderer-scripts compiling' })
|
||||
spinners.add('main', { text: 'main compiling' })
|
||||
const handleResult = (name: TaksName) => {
|
||||
return (success: boolean) => {
|
||||
if (success) {
|
||||
spinners.succeed(name, { text: name + ' compile success!' })
|
||||
} else {
|
||||
spinners.fail(name, { text: name + ' compile fail!' })
|
||||
}
|
||||
return success
|
||||
}
|
||||
}
|
||||
|
||||
const buildTasks = [
|
||||
runBuildWorker('renderer', noop).then(handleResult('renderer')),
|
||||
runBuildWorker('renderer-lyric', noop).then(handleResult('renderer-lyric')),
|
||||
runBuildWorker('renderer-scripts', handleUpdate).then(handleResult('renderer-scripts')),
|
||||
replaceLib({ electronPlatformName: process.platform, arch: Arch[process.arch as any] }).then(async() => {
|
||||
return build(mainConfig, handleUpdate).then(handleResult('main'))
|
||||
}),
|
||||
]
|
||||
|
||||
if (!await Promise.all(buildTasks).then((result) => result.every(s => s))) return
|
||||
// listr.run().then(() => {
|
||||
electronProcess = runElectron()
|
||||
|
||||
logger.info(colors.green('\nAll task build successfully'))
|
||||
// })
|
||||
console.timeEnd('init')
|
||||
}
|
||||
|
||||
void runMainThread()
|
||||
|
||||
|
|
@ -1,140 +0,0 @@
|
|||
import path from 'node:path'
|
||||
import { Worker, MessageChannel } from 'worker_threads'
|
||||
import {
|
||||
type UserConfig,
|
||||
mergeConfig,
|
||||
build as viteBuild,
|
||||
createServer,
|
||||
} from 'vite'
|
||||
|
||||
export type BuildSuatus = 'success' | 'error' | 'updated'
|
||||
export type TaksName = 'main' | 'renderer' | 'renderer-lyric' | 'renderer-scripts'
|
||||
|
||||
/**
|
||||
* build code
|
||||
* @param config vite config
|
||||
* @param onUpdated new build event
|
||||
* @returns is success
|
||||
*/
|
||||
export const build = async(config: UserConfig, onUpdated: () => void): Promise<boolean> => {
|
||||
if (config.mode == 'production') {
|
||||
if (config.build) config.build.watch = null
|
||||
return viteBuild(config).then((output) => {
|
||||
// output
|
||||
// console.log(output)
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
return config.server
|
||||
? createBuildServer(config, onUpdated)
|
||||
: buildDev(config, onUpdated)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* build code in dev
|
||||
* @param config vite config
|
||||
* @param onUpdated new build event
|
||||
* @returns is success
|
||||
*/
|
||||
const buildDev = async(config: UserConfig, onUpdated: () => void) => {
|
||||
return new Promise<boolean>(resolve => {
|
||||
let firstBundle = true
|
||||
let isError = false
|
||||
config = mergeConfig(config, {
|
||||
plugins: [
|
||||
{
|
||||
name: 'vite:file-watcher',
|
||||
buildEnd(err?: Error) {
|
||||
// console.log('buildEnd', err !== undefined, err)
|
||||
isError = err !== undefined
|
||||
},
|
||||
closeBundle() {
|
||||
// console.log('closeBundle')
|
||||
if (firstBundle) {
|
||||
firstBundle = false
|
||||
resolve(!isError)
|
||||
} else {
|
||||
if (isError) return
|
||||
onUpdated()
|
||||
}
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
void viteBuild(config)
|
||||
})
|
||||
}
|
||||
|
||||
export const createBuildServer = async(config: UserConfig, onUpdated: () => void) => {
|
||||
return new Promise<boolean>(resolve => {
|
||||
let firstBundle = true
|
||||
let isError = false
|
||||
void createServer({
|
||||
...mergeConfig(config, {
|
||||
plugins: [
|
||||
{
|
||||
name: 'vite:file-watcher',
|
||||
buildEnd(err?: Error) {
|
||||
// console.log('buildEnd', err !== undefined, err)
|
||||
isError = err !== undefined
|
||||
},
|
||||
closeBundle() {
|
||||
// console.log('closeBundle')
|
||||
if (firstBundle) {
|
||||
firstBundle = false
|
||||
// resolve(!isError)
|
||||
} else {
|
||||
if (isError) return
|
||||
onUpdated()
|
||||
}
|
||||
},
|
||||
},
|
||||
],
|
||||
}),
|
||||
configFile: false,
|
||||
}).then(async server => {
|
||||
return server.listen().then(() => {
|
||||
resolve(true)
|
||||
})
|
||||
}).catch((error) => {
|
||||
console.log(error)
|
||||
resolve(false)
|
||||
})
|
||||
|
||||
// return build(config, () => {
|
||||
// // server.ws.send({ type: 'full-reload' })
|
||||
// onUpdated()
|
||||
// })
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* build code in worker
|
||||
* @param config vite config
|
||||
* @param onUpdated new build event
|
||||
* @returns is success
|
||||
*/
|
||||
export const runBuildWorker = async(taskName: TaksName, onUpdated: () => void) => new Promise<boolean>((resolve) => {
|
||||
const worker = new Worker(path.resolve(__dirname, './worker.ts'), {
|
||||
execArgv: ['--require', 'ts-node/register'],
|
||||
})
|
||||
const subChannel = new MessageChannel()
|
||||
worker.postMessage({ port: subChannel.port1, taskName }, [subChannel.port1])
|
||||
subChannel.port2.on('message', ({ status }: { status: BuildSuatus }) => {
|
||||
// console.log(status)
|
||||
switch (status) {
|
||||
case 'updated':
|
||||
onUpdated()
|
||||
break
|
||||
case 'success':
|
||||
resolve(true)
|
||||
break
|
||||
case 'error':
|
||||
resolve(false)
|
||||
break
|
||||
}
|
||||
})
|
||||
})
|
|
@ -1,33 +0,0 @@
|
|||
import { parentPort, type MessagePort } from 'node:worker_threads'
|
||||
import { type TaksName, build } from './utils'
|
||||
|
||||
import mainConfig from './configs/main'
|
||||
import rendererConfig from './configs/renderer'
|
||||
import rendererLyricConfig from './configs/renderer-lyric'
|
||||
import rendererScriptConfig from './configs/renderer-scripts'
|
||||
|
||||
const configs = {
|
||||
main: mainConfig,
|
||||
renderer: rendererConfig,
|
||||
'renderer-lyric': rendererLyricConfig,
|
||||
'renderer-scripts': rendererScriptConfig,
|
||||
}
|
||||
|
||||
if (!parentPort) throw new Error('Require run in worker')
|
||||
|
||||
parentPort.once('message', ({ port, taskName }: {
|
||||
port: MessagePort
|
||||
taskName: TaksName
|
||||
}) => {
|
||||
// assert(port instanceof MessagePort)
|
||||
const sendStatus = () => {
|
||||
port.postMessage({
|
||||
status: 'updated',
|
||||
})
|
||||
}
|
||||
void build(configs[taskName], sendStatus).then((status) => {
|
||||
port.postMessage({
|
||||
status: status ? 'success' : 'error',
|
||||
})
|
||||
})
|
||||
})
|
|
@ -0,0 +1,12 @@
|
|||
const isDev = process.env.NODE_ENV === 'development'
|
||||
|
||||
module.exports = {
|
||||
// preserveWhitepace: true,
|
||||
compilerOptions: {
|
||||
whitespace: 'preserve',
|
||||
},
|
||||
extractCSS: !isDev,
|
||||
// cssModules: {
|
||||
// localIndetName: '',
|
||||
// },
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
minimize: false,
|
||||
}
|
77
package.json
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "lx-music-desktop",
|
||||
"version": "2.4.0-beta.8",
|
||||
"version": "2.4.0-beta.9",
|
||||
"description": "一个免费的音乐查找助手",
|
||||
"main": "./dist/main/main.js",
|
||||
"main": "./dist/main.js",
|
||||
"productName": "lx-music-desktop",
|
||||
"scripts": {
|
||||
"pack": "ts-node build-config/pack.js && npm run pack:win:setup:x64",
|
||||
"pack:win": "ts-node build-config/pack.js && npm run pack:win:setup:x64 && npm run pack:win:setup:x86 && npm run pack:win:setup:arm64 && npm run pack:win:setup:x86_64 && npm run pack:win:7z",
|
||||
"pack": "node build-config/pack.js && npm run pack:win:setup:x64",
|
||||
"pack:win": "node build-config/pack.js && npm run pack:win:setup:x64 && npm run pack:win:setup:x86 && npm run pack:win:setup:arm64 && npm run pack:win:setup:x86_64 && npm run pack:win:7z",
|
||||
"pack:win:setup:x86_64": "cross-env TARGET=Setup ARCH=x86_64 electron-builder -w=nsis --x64 --ia32 -p never",
|
||||
"pack:win:setup:x64": "cross-env TARGET=Setup ARCH=x64 electron-builder -w=nsis --x64 -p never",
|
||||
"pack:win:setup:x86": "cross-env TARGET=Setup ARCH=x86 electron-builder -w=nsis --ia32 -p never",
|
||||
|
@ -19,7 +19,7 @@
|
|||
"pack:win:7z:x64": "cross-env TARGET=green ARCH=win_x64 electron-builder -w=7z --x64 -p never",
|
||||
"pack:win:7z:x86": "cross-env TARGET=green ARCH=win_x86 electron-builder -w=7z --ia32 -p never",
|
||||
"pack:win:7z:arm64": "cross-env TARGET=green ARCH=win_arm64 electron-builder -w=7z --arm64 -p never",
|
||||
"pack:linux": "ts-node build-config/pack.js && npm run pack:linux:deb && npm run pack:linux:appImage && npm run pack:linux:rpm && npm run pack:linux:pacman",
|
||||
"pack:linux": "node build-config/pack.js && npm run pack:linux:deb && npm run pack:linux:appImage && npm run pack:linux:rpm && npm run pack:linux:pacman",
|
||||
"pack:linux:appImage": "cross-env ARCH=x64 electron-builder -l=AppImage -p never",
|
||||
"pack:linux:deb": "npm run pack:linux:deb:x64 && npm run pack:linux:deb:arm64 && npm run pack:linux:deb:armv7l",
|
||||
"pack:linux:deb:x64": "cross-env ARCH=x64 electron-builder -l=deb --x64 -p never",
|
||||
|
@ -27,10 +27,10 @@
|
|||
"pack:linux:deb:armv7l": "cross-env ARCH=armv7l electron-builder -l=deb --armv7l -p never",
|
||||
"pack:linux:rpm": "cross-env ARCH=x64 electron-builder -l=rpm --x64 -p never",
|
||||
"pack:linux:pacman": "cross-env ARCH=x64 electron-builder -l=pacman --x64 -p never",
|
||||
"pack:mac": "ts-node build-config/pack.js && npm run pack:mac:dmg && npm run pack:mac:dmg:arm64",
|
||||
"pack:mac": "node build-config/pack.js && npm run pack:mac:dmg && npm run pack:mac:dmg:arm64",
|
||||
"pack:mac:dmg": "cross-env electron-builder -m=dmg -p never",
|
||||
"pack:mac:dmg:arm64": "cross-env electron-builder -m=dmg --arm64 -p never",
|
||||
"pack:dir": "ts-node build-config/pack.js && electron-builder --dir",
|
||||
"pack:dir": "node build-config/pack.js && electron-builder --dir",
|
||||
"publish": "node publish",
|
||||
"publish:win:setup:x64:always": "cross-env TARGET=Setup ARCH=x64 electron-builder -w=nsis --x64 -p always",
|
||||
"publish:win:setup:x64": "cross-env TARGET=Setup ARCH=x64 electron-builder -w=nsis --x64 -p always",
|
||||
|
@ -54,12 +54,16 @@
|
|||
"publish:linux:appImage": "cross-env ARCH=x64 electron-builder -l=AppImage -p onTagOrDraft",
|
||||
"publish:linux:rpm": "cross-env ARCH=x64 electron-builder -l=rpm --x64 -p onTagOrDraft",
|
||||
"publish:linux:pacman": "cross-env ARCH=x64 electron-builder -l=pacman --x64 -p onTagOrDraft",
|
||||
"dev": "cross-env NODE_OPTIONS=--max-http-header-size=200000 ts-node build-config/runner-dev.js",
|
||||
"dev": "cross-env NODE_OPTIONS=--max-http-header-size=200000 node build-config/runner-dev.js",
|
||||
"build:theme": "node src/common/theme/createThemes.js",
|
||||
"build": "ts-node build-config/pack.js",
|
||||
"lint": "eslint --ext .ts,.js,.vue src",
|
||||
"lint:fix": "eslint --ext .ts,.js,.vue --fix src",
|
||||
"postinstall": "node ./build-config/dependencies-patch.js && electron-builder install-app-deps",
|
||||
"build": "node build-config/pack.js",
|
||||
"build:main": "cross-env NODE_ENV=production webpack --config build-config/main/webpack.config.prod.js --progress",
|
||||
"build:renderer": "cross-env NODE_ENV=production webpack --config build-config/renderer/webpack.config.prod.js --progress",
|
||||
"build:renderer-lyric": "cross-env NODE_ENV=production webpack --config build-config/renderer-lyric/webpack.config.prod.js --progress",
|
||||
"build:renderer-scripts": "cross-env NODE_ENV=production webpack --config build-config/renderer-scripts/webpack.config.prod.js --progress",
|
||||
"lint": "eslint --ext .ts,.js,.vue -f node_modules/eslint-formatter-friendly src",
|
||||
"lint:fix": "eslint --ext .ts,.js,.vue -f node_modules/eslint-formatter-friendly --fix src",
|
||||
"postinstall": "electron-builder install-app-deps",
|
||||
"dp": "cross-env ELECTRON_GET_USE_PROXY=true GLOBAL_AGENT_HTTPS_PROXY=http://127.0.0.1:2081 npm run pack",
|
||||
"up": "cross-env ELECTRON_GET_USE_PROXY=true GLOBAL_AGENT_HTTPS_PROXY=http://127.0.0.1:2081 npm i"
|
||||
},
|
||||
|
@ -212,41 +216,66 @@
|
|||
"@tsconfig/recommended": "^1.0.2",
|
||||
"@types/better-sqlite3": "^7.6.4",
|
||||
"@types/needle": "^3.2.0",
|
||||
"@types/node": "^20.4.10",
|
||||
"@types/spinnies": "^0.5.0",
|
||||
"@types/tunnel": "^0.0.3",
|
||||
"@types/ws": "8.5.4",
|
||||
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
||||
"@typescript-eslint/parser": "^5.62.0",
|
||||
"@vitejs/plugin-vue": "^4.2.3",
|
||||
"@vue/eslint-config-typescript": "^11.0.3",
|
||||
"@volar/vue-language-plugin-pug": "^1.6.5",
|
||||
"@vue/language-plugin-pug": "^1.8.8",
|
||||
"@vue/tsconfig": "^0.4.0",
|
||||
"babel-loader": "^9.1.3",
|
||||
"browserslist": "^4.21.10",
|
||||
"chalk": "^4.1.2",
|
||||
"changelog-parser": "^3.0.1",
|
||||
"copy-webpack-plugin": "^11.0.0",
|
||||
"core-js": "^3.32.0",
|
||||
"cross-env": "^7.0.3",
|
||||
"css-loader": "^6.8.1",
|
||||
"css-minimizer-webpack-plugin": "^5.0.1",
|
||||
"del": "^6.1.1",
|
||||
"electron": "^22.3.18",
|
||||
"electron": "^22.3.21",
|
||||
"electron-builder": "^24.6.3",
|
||||
"electron-debug": "^3.2.0",
|
||||
"electron-devtools-installer": "^3.2.0",
|
||||
"electron-to-chromium": "^1.4.490",
|
||||
"electron-to-chromium": "^1.4.494",
|
||||
"electron-updater": "^6.1.4",
|
||||
"eslint": "^8.47.0",
|
||||
"eslint-config-standard": "^17.1.0",
|
||||
"eslint-config-standard-with-typescript": "^35.0.0",
|
||||
"eslint-formatter-friendly": "github:lyswhut/eslint-friendly-formatter#2170d1320e2fad13615a9dcf229669f0bb473a53",
|
||||
"eslint-plugin-html": "^7.1.0",
|
||||
"eslint-plugin-import": "^2.28.0",
|
||||
"eslint-plugin-n": "^15.7.0",
|
||||
"eslint-plugin-promise": "^6.1.1",
|
||||
"eslint-plugin-vue": "^9.17.0",
|
||||
"eslint-plugin-vue-pug": "^0.6.0",
|
||||
"eslint-webpack-plugin": "^4.0.1",
|
||||
"html-webpack-plugin": "^5.5.3",
|
||||
"less": "^4.2.0",
|
||||
"less-loader": "^11.1.3",
|
||||
"mini-css-extract-plugin": "^2.7.6",
|
||||
"node-loader": "^2.0.0",
|
||||
"postcss": "^8.4.28",
|
||||
"postcss-loader": "^7.3.3",
|
||||
"postcss-pxtorem": "^6.0.0",
|
||||
"pug": "^3.0.2",
|
||||
"pug-plain-loader": "^1.1.0",
|
||||
"rimraf": "^5.0.1",
|
||||
"spinnies": "github:lyswhut/spinnies#233305c58694aa3b053e3ab9af9049993f918b9d",
|
||||
"ts-node": "^10.9.1",
|
||||
"svg-sprite-loader": "^6.0.11",
|
||||
"svg-transform-loader": "^2.0.13",
|
||||
"svgo-loader": "^4.0.0",
|
||||
"terser": "^5.19.2",
|
||||
"terser-webpack-plugin": "^5.3.9",
|
||||
"ts-loader": "^9.4.4",
|
||||
"typescript": "^5.1.6",
|
||||
"vite": "^4.4.9",
|
||||
"vite-plugin-electron-renderer": "^0.14.5",
|
||||
"vite-plugin-svg-icons": "^2.0.1",
|
||||
"vue-eslint-parser": "^9.3.1"
|
||||
"vue-eslint-parser": "^9.3.1",
|
||||
"vue-loader": "^17.2.2",
|
||||
"vue-template-compiler": "^2.7.14",
|
||||
"webpack": "^5.88.2",
|
||||
"webpack-cli": "^5.1.4",
|
||||
"webpack-dev-server": "^4.15.1",
|
||||
"webpack-hot-middleware": "github:lyswhut/webpack-hot-middleware#329c4375134b89d39da23a56a94db651247c74a1",
|
||||
"webpack-merge": "^5.9.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@simonwep/pickr": "^1.8.2",
|
||||
|
|
|
@ -30,5 +30,4 @@
|
|||
|
||||
### 其他
|
||||
|
||||
- 更新 electron 到 v22.3.18
|
||||
- 代码构建工具从webpack迁移到vite,提升代码打包速度与开发模式启动速度(在我电脑上构建时间从60s降到21s,开发模式启动时间从60s降到10s)
|
||||
- 更新 electron 到 v22.3.21
|
||||
|
|
Before Width: | Height: | Size: 1.3 MiB After Width: | Height: | Size: 1.3 MiB |
Before Width: | Height: | Size: 353 KiB After Width: | Height: | Size: 353 KiB |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 1.1 MiB |
Before Width: | Height: | Size: 997 KiB After Width: | Height: | Size: 997 KiB |
|
@ -21,8 +21,8 @@ export const initGlobalData = () => {
|
|||
|
||||
global.staticPath =
|
||||
process.env.NODE_ENV !== 'production'
|
||||
? __STATIC_PATH__
|
||||
: path.join(encodePath(__dirname), '../static')
|
||||
? webpackStaticPath
|
||||
: path.join(encodePath(__dirname), 'static')
|
||||
}
|
||||
|
||||
export const initSingleInstanceHandle = () => {
|
||||
|
|
|
@ -26,5 +26,5 @@ app.on('ready', () => {
|
|||
})
|
||||
|
||||
// Require `main` process to boot app
|
||||
import('./index')
|
||||
require('./index')
|
||||
|
||||
|
|
|
@ -27,16 +27,15 @@ const winEvent = () => {
|
|||
|
||||
export const createWindow = async(userApi: LX.UserApi.UserApiInfo) => {
|
||||
await closeWindow()
|
||||
dir ??= process.env.NODE_ENV !== 'production' ? path.join(__USER_API_PATH__, 'renderer') : encodePath(__dirname)
|
||||
dir ??= process.env.NODE_ENV !== 'production' ? webpackUserApiPath : path.join(encodePath(__dirname), 'userApi')
|
||||
|
||||
if (!html) {
|
||||
html = await fs.promises.readFile(path.join(dir, 'user-api.html'), 'utf8')
|
||||
html = await fs.promises.readFile(path.join(dir, 'renderer/user-api.html'), 'utf8')
|
||||
}
|
||||
const preloadUrl = process.env.NODE_ENV !== 'production'
|
||||
? `${path.join(encodePath(__dirname), '../dist/user-api-preload.js')}`
|
||||
: `${path.join(encodePath(__dirname), '../preload/user-api-preload.js')}`
|
||||
|
||||
// console.log(preloadUrl, html)
|
||||
: `${path.join(encodePath(__dirname), 'user-api-preload.js')}`
|
||||
// console.log(preloadUrl)
|
||||
|
||||
/**
|
||||
* Initial window options
|
||||
|
|
|
@ -139,7 +139,7 @@ export const createWindow = () => {
|
|||
},
|
||||
})
|
||||
|
||||
const winURL = process.env.NODE_ENV !== 'production' ? 'http://localhost:9081' : `file://${path.join(encodePath(__dirname), '../renderer-lyric/index.html')}`
|
||||
const winURL = process.env.NODE_ENV !== 'production' ? 'http://localhost:9081/lyric.html' : `file://${path.join(encodePath(__dirname), 'lyric.html')}`
|
||||
void browserWindow.loadURL(winURL + `?dark=${shouldUseDarkColors}&theme=${encodeURIComponent(JSON.stringify(theme))}`)
|
||||
|
||||
winEvent()
|
||||
|
|
|
@ -87,7 +87,6 @@ export const watchConfigKeys = [
|
|||
export const buildLyricConfig = (appSetting: Partial<LX.AppSetting>): Partial<LX.DesktopLyric.Config> => {
|
||||
const setting: Partial<LX.DesktopLyric.Config> = {}
|
||||
for (const key of watchConfigKeys) {
|
||||
// @ts-expect-error
|
||||
if (key in appSetting) setting[key] = appSetting[key]
|
||||
}
|
||||
return setting
|
||||
|
|
|
@ -99,7 +99,7 @@ export const createWindow = () => {
|
|||
}
|
||||
browserWindow = new BrowserWindow(options)
|
||||
|
||||
const winURL = process.env.NODE_ENV !== 'production' ? 'http://localhost:9080' : `file://${path.join(encodePath(__dirname), '../renderer/index.html')}`
|
||||
const winURL = process.env.NODE_ENV !== 'production' ? 'http://localhost:9080' : `file://${path.join(encodePath(__dirname), 'index.html')}`
|
||||
void browserWindow.loadURL(winURL + `?dt=${!!global.envParams.cmdParams.dt}&dark=${shouldUseDarkColors}&theme=${encodeURIComponent(JSON.stringify(theme))}`)
|
||||
|
||||
winEvent()
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { createInflate, constants as zlibConstants } from 'node:zlib'
|
||||
import path from 'node:path'
|
||||
// import path from 'path'
|
||||
import { mainHandle } from '@common/mainIpc'
|
||||
import { WIN_MAIN_RENDERER_EVENT_NAME } from '@common/ipcNames'
|
||||
|
||||
|
@ -40,7 +40,7 @@ const handleDecode = async(lrc: string, tlrc: string, rlrc: string) => {
|
|||
// const nativeBindingPath = path.join(__dirname, '../build/Release/qrc_decode.node')
|
||||
// const nativeBindingPath = process.env.NODE_ENV !== 'production' ? path.join(__dirname, '../build/Release/qrc_decode.node')
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const addon = require(path.join(__QRC_DECODE_NODE_PATH__, 'qrc_decode.node'))
|
||||
const addon = require('qrc_decode.node')
|
||||
// console.log(addon)
|
||||
qrc_decode = addon.qrc_decode
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"resolveJsonModule": true,
|
||||
"typeRoots": [
|
||||
"./types"
|
||||
],
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
// // }
|
||||
// // }
|
||||
|
||||
declare const __STATIC_PATH__: string
|
||||
declare const __USER_API_PATH__: string
|
||||
declare const __QRC_DECODE_NODE_PATH__: string
|
||||
declare const webpackStaticPath: string
|
||||
declare const webpackUserApiPath: string
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ const initTables = (db: Database.Database) => {
|
|||
// 打开、初始化数据库
|
||||
export const init = (lxDataPath: string): boolean | null => {
|
||||
const databasePath = path.join(lxDataPath, 'lx.data.db')
|
||||
const nativeBinding = path.join(__dirname, '../../node_modules/better-sqlite3/build/Release/better_sqlite3.node')
|
||||
const nativeBinding = path.join(__dirname, '../node_modules/better-sqlite3/build/Release/better_sqlite3.node')
|
||||
let dbFileExists = true
|
||||
|
||||
try {
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
import { Worker } from 'node:worker_threads'
|
||||
import * as Comlink from 'comlink'
|
||||
import nodeEndpoint from 'comlink/dist/esm/node-adapter'
|
||||
import path from 'node:path'
|
||||
// import dbService from '../dbService/index'
|
||||
|
||||
export declare type DBSeriveTypes = Comlink.Remote<LX.WorkerDBSeriveListTypes>
|
||||
export type DBSeriveTypes = Comlink.Remote<LX.WorkerDBSeriveListTypes>
|
||||
|
||||
export const createDBServiceWorker = () => {
|
||||
// console.log(new URL('../dbService', import.meta.url))
|
||||
// console.log(__dirname)
|
||||
const worker: Worker = new Worker(path.join(__dirname, './dbService.worker'))
|
||||
const worker: Worker = new Worker(new URL(
|
||||
/* webpackChunkName: 'dbService.worker' */
|
||||
'../dbService',
|
||||
import.meta.url,
|
||||
))
|
||||
return Comlink.wrap<LX.WorkerDBSeriveListTypes>(nodeEndpoint(worker))
|
||||
}
|
||||
|
||||
|
|
|
@ -1,22 +1,25 @@
|
|||
import upperFirst from 'lodash/upperFirst'
|
||||
import camelCase from 'lodash/camelCase'
|
||||
|
||||
const requireComponent = import.meta.glob(['./**/*.vue', '!./**/components/**/*.vue'], { eager: true })
|
||||
const vueFileRxp = /\.vue$/
|
||||
const vueIndexFileRxp = /\/index\.vue$/
|
||||
const requireComponent = require.context('./', true, /\.vue$/)
|
||||
|
||||
const vueFileRxp = /\.vue$/
|
||||
|
||||
export default app => {
|
||||
Object.entries(requireComponent).forEach(([path, module]) => {
|
||||
path = path.replace(/^\.\//, '')
|
||||
let fileName = vueIndexFileRxp.test(path)
|
||||
? path.replace(vueIndexFileRxp, '')
|
||||
: path.replace(vueFileRxp, '')
|
||||
requireComponent.keys().forEach(fileName => {
|
||||
const filePath = fileName.replace(/^\.\//, '')
|
||||
|
||||
let componentName = upperFirst(camelCase(fileName))
|
||||
if (!filePath.split('/').every((path, index, arr) => {
|
||||
const char = path.charAt(0)
|
||||
return vueFileRxp.test(path) || char.toUpperCase() !== char || arr[index + 1] == 'index.vue'
|
||||
})) return
|
||||
|
||||
// console.log(componentName)
|
||||
const componentConfig = requireComponent(fileName)
|
||||
|
||||
app.component(componentName, module.default)
|
||||
let componentName = upperFirst(camelCase(filePath.replace(/\.\w+$/, '')))
|
||||
|
||||
if (componentName.endsWith('Index')) componentName = componentName.replace(/Index$/, '')
|
||||
|
||||
app.component(componentName, componentConfig.default || componentConfig)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -27,6 +27,5 @@
|
|||
}
|
||||
if (/theme=(.+)(#|$)/.test(window.location.search)) applyThemeColor(RegExp.$1)
|
||||
</script>
|
||||
<script type="module" src="/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,22 +1,25 @@
|
|||
import upperFirst from 'lodash/upperFirst'
|
||||
import camelCase from 'lodash/camelCase'
|
||||
|
||||
const requireComponent = import.meta.glob(['./**/*.vue', '!./**/components/**/*.vue'], { eager: true })
|
||||
const vueFileRxp = /\.vue$/
|
||||
const vueIndexFileRxp = /\/index\.vue$/
|
||||
const requireComponent = require.context('./', true, /\.vue$/)
|
||||
|
||||
const vueFileRxp = /\.vue$/
|
||||
|
||||
export default app => {
|
||||
Object.entries(requireComponent).forEach(([path, module]) => {
|
||||
path = path.replace(/^\.\//, '')
|
||||
let fileName = vueIndexFileRxp.test(path)
|
||||
? path.replace(vueIndexFileRxp, '')
|
||||
: path.replace(vueFileRxp, '')
|
||||
requireComponent.keys().forEach(fileName => {
|
||||
const filePath = fileName.replace(/^\.\//, '')
|
||||
|
||||
let componentName = upperFirst(camelCase(fileName))
|
||||
if (!filePath.split('/').every((path, index, arr) => {
|
||||
const char = path.charAt(0)
|
||||
return vueFileRxp.test(path) || char.toUpperCase() !== char || arr[index + 1] == 'index.vue'
|
||||
})) return
|
||||
|
||||
// console.log(componentName)
|
||||
const componentConfig = requireComponent(fileName)
|
||||
|
||||
app.component(componentName, module.default)
|
||||
let componentName = upperFirst(camelCase(filePath.replace(/\.\w+$/, '')))
|
||||
|
||||
if (componentName.endsWith('Index')) componentName = componentName.replace(/Index$/, '')
|
||||
|
||||
app.component(componentName, componentConfig.default || componentConfig)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -3,13 +3,12 @@ import { getDuration, getPlaybackRate, getCurrentTime } from '@renderer/plugins/
|
|||
import { isPlay, musicInfo, playMusicInfo } from '@renderer/store/player/state'
|
||||
import { playProgress } from '@renderer/store/player/playProgress'
|
||||
import { pause, play, playNext, playPrev, stop } from '@renderer/core/player'
|
||||
import silenceAudio from '@renderer/assets/medias/Silence02s.mp3'
|
||||
|
||||
export default () => {
|
||||
// 创建一个空白音频以保持对 Media Session 的注册
|
||||
const emptyAudio = new Audio()
|
||||
emptyAudio.autoplay = false
|
||||
emptyAudio.src = silenceAudio
|
||||
emptyAudio.src = require('@renderer/assets/medias/Silence02s.mp3')
|
||||
emptyAudio.controls = false
|
||||
emptyAudio.preload = 'auto'
|
||||
emptyAudio.onplaying = () => {
|
||||
|
|
|
@ -16,41 +16,40 @@ import {
|
|||
import { appSetting } from '@renderer/store/setting'
|
||||
|
||||
const cache = new Map<string, AudioBuffer>()
|
||||
const loadBuffer = async(name: string) => {
|
||||
const path = (await import(`../../../assets/medias/filters/${name.replace('.wav', '')}.wav`)).default as string
|
||||
return new Promise<AudioBuffer>((resolve, reject) => {
|
||||
if (cache.has(path)) {
|
||||
resolve(cache.get(path) as AudioBuffer)
|
||||
return
|
||||
}
|
||||
// Load buffer asynchronously
|
||||
let request = new XMLHttpRequest()
|
||||
request.open('GET', path, true)
|
||||
request.responseType = 'arraybuffer'
|
||||
const loadBuffer = async(name: string) => new Promise<AudioBuffer>((resolve, reject) => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const path = require('@renderer/assets/medias/filters/' + name) as string
|
||||
if (cache.has(path)) {
|
||||
resolve(cache.get(path) as AudioBuffer)
|
||||
return
|
||||
}
|
||||
// Load buffer asynchronously
|
||||
let request = new XMLHttpRequest()
|
||||
request.open('GET', path, true)
|
||||
request.responseType = 'arraybuffer'
|
||||
|
||||
request.onload = function() {
|
||||
// Asynchronously decode the audio file data in request.response
|
||||
void getAudioContext().decodeAudioData(request.response, (buffer) => {
|
||||
if (!buffer) {
|
||||
reject(new Error('error decoding file data: ' + path))
|
||||
return
|
||||
}
|
||||
cache.set(path, buffer)
|
||||
resolve(buffer)
|
||||
},
|
||||
function(error) {
|
||||
reject(error)
|
||||
console.error('decodeAudioData error', error)
|
||||
})
|
||||
}
|
||||
request.onload = function() {
|
||||
// Asynchronously decode the audio file data in request.response
|
||||
void getAudioContext().decodeAudioData(request.response, (buffer) => {
|
||||
if (!buffer) {
|
||||
reject(new Error('error decoding file data: ' + path))
|
||||
return
|
||||
}
|
||||
cache.set(path, buffer)
|
||||
resolve(buffer)
|
||||
},
|
||||
function(error) {
|
||||
reject(error)
|
||||
console.error('decodeAudioData error', error)
|
||||
})
|
||||
}
|
||||
|
||||
request.onerror = function() {
|
||||
reject(new Error('XHR error'))
|
||||
}
|
||||
request.onerror = function() {
|
||||
reject(new Error('XHR error'))
|
||||
}
|
||||
|
||||
request.send()
|
||||
})
|
||||
}
|
||||
request.send()
|
||||
})
|
||||
|
||||
export default () => {
|
||||
// console.log(appSetting['player.soundEffect.panner.enable'])
|
||||
|
|
|
@ -31,6 +31,5 @@
|
|||
}
|
||||
if (/theme=(.+)(#|$)/.test(window.location.search)) applyThemeColor(RegExp.$1)
|
||||
</script>
|
||||
<script type="module" src="/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import '@common/error'
|
||||
import 'virtual:svg-icons-register'
|
||||
import { createApp } from 'vue'
|
||||
|
||||
import './core/globalData'
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import SvgIcon from './SvgIcon.vue'
|
||||
|
||||
// const req = require.context('@renderer/assets/svgs', false, /\.svg$/)
|
||||
// const requireAll = requireContext => requireContext.keys().map(requireContext)
|
||||
// requireAll(req)
|
||||
const req = require.context('@renderer/assets/svgs', false, /\.svg$/)
|
||||
const requireAll = requireContext => requireContext.keys().map(requireContext)
|
||||
requireAll(req)
|
||||
|
||||
export default app => {
|
||||
app.component('svg-icon', SvgIcon)
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import PhaseVocoder from './pitch-shifter/phase-vocoder.js?worker&url'
|
||||
|
||||
let audio: HTMLAudioElement | null = null
|
||||
let audioContext: AudioContext
|
||||
let mediaSource: MediaElementAudioSourceNode
|
||||
|
@ -278,7 +276,11 @@ const loadPitchShifterNode = () => {
|
|||
pitchShifterNodeLoadStatus = 'loading'
|
||||
initAdvancedAudioFeatures()
|
||||
// source -> analyser -> biquadFilter -> audioWorklet(pitch shifter) -> [(convolver & convolverSource)->convolverDynamicsCompressor] -> panner -> gain
|
||||
void audioContext.audioWorklet.addModule(PhaseVocoder).then(() => {
|
||||
void audioContext.audioWorklet.addModule(new URL(
|
||||
/* webpackChunkName: 'pitch_shifter.audioWorklet' */
|
||||
'./pitch-shifter/phase-vocoder.js',
|
||||
import.meta.url,
|
||||
)).then(() => {
|
||||
console.log('pitch shifter audio worklet loaded')
|
||||
// https://github.com/olvb/phaze/issues/26#issuecomment-1574629971
|
||||
pitchShifterNode = new AudioWorkletNode(audioContext, 'phase-vocoder-processor', { outputChannelCount: [2] })
|
||||
|
|
|
@ -2,14 +2,6 @@
|
|||
// import Vue from 'vue'
|
||||
import { createRouter, createWebHashHistory } from 'vue-router'
|
||||
|
||||
import SearchView from './views/Search/index.vue'
|
||||
import SongListView from './views/songList/List/index.vue'
|
||||
import SongListDetailView from './views/songList/Detail/index.vue'
|
||||
import LeaderboardView from './views/Leaderboard/index.vue'
|
||||
import ListView from './views/List/index.vue'
|
||||
import DownloadView from './views/Download/index.vue'
|
||||
import SettingView from './views/Setting/index.vue'
|
||||
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHashHistory(),
|
||||
|
@ -17,7 +9,7 @@ const router = createRouter({
|
|||
{
|
||||
path: '/search',
|
||||
name: 'Search',
|
||||
component: SearchView,
|
||||
component: require('./views/Search/index.vue').default,
|
||||
meta: {
|
||||
name: 'Search',
|
||||
},
|
||||
|
@ -25,7 +17,7 @@ const router = createRouter({
|
|||
{
|
||||
path: '/songList/list',
|
||||
name: 'SongList',
|
||||
component: SongListView,
|
||||
component: require('./views/songList/List/index.vue').default,
|
||||
meta: {
|
||||
name: 'SongList',
|
||||
},
|
||||
|
@ -33,7 +25,7 @@ const router = createRouter({
|
|||
{
|
||||
path: '/songList/detail',
|
||||
name: 'SongListDetail',
|
||||
component: SongListDetailView,
|
||||
component: require('./views/songList/Detail/index.vue').default,
|
||||
meta: {
|
||||
name: 'SongList',
|
||||
},
|
||||
|
@ -41,7 +33,7 @@ const router = createRouter({
|
|||
{
|
||||
path: '/leaderboard',
|
||||
name: 'Leaderboard',
|
||||
component: LeaderboardView,
|
||||
component: require('./views/Leaderboard/index.vue').default,
|
||||
meta: {
|
||||
name: 'Leaderboard',
|
||||
},
|
||||
|
@ -49,7 +41,7 @@ const router = createRouter({
|
|||
{
|
||||
path: '/list',
|
||||
name: 'List',
|
||||
component: ListView,
|
||||
component: require('./views/List/index.vue').default,
|
||||
meta: {
|
||||
name: 'List',
|
||||
},
|
||||
|
@ -57,7 +49,7 @@ const router = createRouter({
|
|||
{
|
||||
path: '/download',
|
||||
name: 'Download',
|
||||
component: DownloadView,
|
||||
component: require('./views/Download/index.vue').default,
|
||||
meta: {
|
||||
name: 'Download',
|
||||
},
|
||||
|
@ -65,7 +57,7 @@ const router = createRouter({
|
|||
{
|
||||
path: '/setting',
|
||||
name: 'Setting',
|
||||
component: SettingView,
|
||||
component: require('./views/Setting/index.vue').default,
|
||||
meta: {
|
||||
name: 'Setting',
|
||||
},
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { ref, reactive, shallowRef, markRaw, computed, watch } from '@common/utils/vueTools'
|
||||
import { windowSizeList as configWindowSizeList } from '@common/config'
|
||||
import { appSetting } from './setting'
|
||||
import { version } from '../../../package.json'
|
||||
import pkg from '../../../package.json'
|
||||
import { type ProgressInfo } from 'electron-updater'
|
||||
import music from '@renderer/utils/musicSdk'
|
||||
process.versions.app = version
|
||||
process.versions.app = pkg.version
|
||||
|
||||
export const apiSource = ref<string | null>(null)
|
||||
export const proxy: {
|
||||
|
@ -115,7 +115,7 @@ export const versionInfo = window.lxData.versionInfo = reactive<{
|
|||
status: LX.UpdateStatus
|
||||
downloadProgress: ProgressInfo | null
|
||||
}>({
|
||||
version,
|
||||
version: pkg.version,
|
||||
newVersion: null,
|
||||
showModal: false,
|
||||
reCheck: false,
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
|
||||
/// <reference types="vite/client" />
|
|
@ -33,7 +33,7 @@ dd
|
|||
.gap-top
|
||||
base-checkbox(id="setting_to_tray" :model-value="appSetting['tray.enable']" :label="$t('setting__basic_to_tray')" @update:model-value="updateSetting({'tray.enable': $event})")
|
||||
.p.gap-top
|
||||
base-btn.btn(min @click="isShowPlayTimeoutModal = true") {{ $t('setting__play_timeout')}} {{ timeLabel ? ` (${timeLabel})` : '' }}
|
||||
base-btn.btn(min @click="isShowPlayTimeoutModal = true") {{ $t('setting__play_timeout')}} {{ timeLabel ? ` (${timeLabel})` : '' }}
|
||||
|
||||
dd
|
||||
h3#basic_source {{ $t('setting__basic_source') }}
|
||||
|
|
|
@ -3,9 +3,11 @@ import * as Comlink from 'comlink'
|
|||
export type MainTypes = Comlink.Remote<LX.WorkerMainTypes>
|
||||
|
||||
export const createMainWorker = () => {
|
||||
const worker: Worker = new Worker(new URL('../main', import.meta.url), {
|
||||
type: 'module',
|
||||
})
|
||||
const worker: Worker = new Worker(new URL(
|
||||
/* webpackChunkName: 'renderer.main.worker' */
|
||||
'../main',
|
||||
import.meta.url,
|
||||
))
|
||||
return Comlink.wrap<LX.WorkerMainTypes>(worker)
|
||||
}
|
||||
|
||||
|
@ -20,14 +22,11 @@ export const createMainWorker = () => {
|
|||
|
||||
export type DownloadTypes = Comlink.Remote<LX.WorkerDownloadTypes>
|
||||
export const createDownloadWorker = () => {
|
||||
const worker: Worker = new Worker(new URL('../download', import.meta.url), {
|
||||
type: 'module',
|
||||
})
|
||||
// const worker: Worker = new Worker(new URL(
|
||||
// /* webpackChunkName: 'renderer.download.worker' */
|
||||
// '../download',
|
||||
// import.meta.url,
|
||||
// ))
|
||||
const worker: Worker = new Worker(new URL(
|
||||
/* webpackChunkName: 'renderer.download.worker' */
|
||||
'../download',
|
||||
import.meta.url,
|
||||
))
|
||||
return Comlink.wrap<LX.WorkerDownloadTypes>(worker)
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
"compilerOptions": {
|
||||
"target": "ESNext",
|
||||
"allowJs": true,
|
||||
"module": "esnext",
|
||||
"resolveJsonModule": true,
|
||||
"moduleResolution": "nodenext",
|
||||
"outDir": "./dist",
|
||||
"baseUrl": "./src", /* Specify the base directory to resolve non-relative module names. */
|
||||
// "paths": { /* Specify a set of entries that re-map imports to additional lookup locations. */
|
||||
|
|