Skip to content

Commit

Permalink
feat: worker socket (#3)
Browse files Browse the repository at this point in the history
* feat: worker socket

Signed-off-by: Innei <i@innei.in>

* fix: get sid

Signed-off-by: Innei <i@innei.in>

* fix: ws connect

Signed-off-by: Innei <i@innei.in>

---------

Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Apr 7, 2024
1 parent 659fdb7 commit 550abd7
Show file tree
Hide file tree
Showing 9 changed files with 817 additions and 39 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ next-env.d.ts
.vscode/sftp.json

src/app/dev

/public/static
60 changes: 39 additions & 21 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { execSync } from 'child_process'
import path from 'path'
import { config } from 'dotenv'
import path from 'path'

import CopyPlugin from 'copy-webpack-plugin'
import NextBundleAnalyzer from '@next/bundle-analyzer'

// const pkg = require('./package.json')
import pkg from './package.json' assert {type: 'json'}

const __dirname = path.resolve()

process.title = 'Shiro (NextJS)'

const env = config().parsed || {}
Expand Down Expand Up @@ -80,27 +84,41 @@ let nextConfig = {
'utf-8-validate': 'commonjs utf-8-validate',
bufferutil: 'commonjs bufferutil',
})
config.module.rules.push({
test: /\.worker\.js$/,
loader: 'worker-loader',
options: {
publicPath: '/_next/',
worker: {
type: "SharedWorker",
// https://v4.webpack.js.org/loaders/worker-loader/#worker
options: {
name: "shiro-ws-worker",
},
},

// config.plugins.push(
// new webpack.optimize.MinChunkSizePlugin({
// minChunkSize: 1024 * 100, // Minimum number of characters
// }),
// )

// if (
// process.env.SENTRY === 'true' &&
// process.env.NEXT_PUBLIC_SENTRY_DSN &&
// isProd
// ) {
// config.plugins.push(
// sentryWebpackPlugin({
// org: 'inneis-site',
//
// project: 'springtide',
// authToken: process.env.SENTRY_AUTH_TOKEN,
// }),
// )
// }
},
})

// plugins
config.plugins.push(
new CopyPlugin({
patterns: [
{
from: path.resolve(
__dirname,
'./node_modules/socket.io-client/dist/socket.io.min.js',
),
to: path.resolve(__dirname, './public/static/socket.io.js'),
},
],
}),
)

config.resolve.alias['socket.io-client'] = path.resolve(
__dirname,
'./public/static/socket.io.js',
)

return config
},
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
"@types/remove-markdown": "0.3.4",
"@types/rss": "0.0.32",
"autoprefixer": "10.4.19",
"copy-webpack-plugin": "12.0.2",
"cross-env": "7.0.3",
"dotenv": "16.4.5",
"eslint": "8.57.0",
Expand All @@ -162,6 +163,7 @@
"tailwind-variants": "0.2.1",
"tailwindcss": "^3.4.3",
"typescript": "5.4.4",
"worker-loader": "3.0.8",
"zx": "7.2.3"
},
"nextBundleAnalysis": {
Expand Down Expand Up @@ -189,4 +191,4 @@
"string.prototype.matchall": "npm:@nolyfill/string.prototype.matchall@latest"
}
}
}
}
Loading

0 comments on commit 550abd7

Please sign in to comment.