td
td copied to clipboard
Building tdweb
Hello!
It's not an issue but I was able to build the tdweb using the latest version of emsdk by upgrading the webpack to latest version. Please input your review.
Following changes I made in installation process
./emsdk install latest && ./emsdk activate latest && source emsdk_env.sh
Following changes in the code base:
build-tdlib.sh
cmake --build build/asmjs --target td_asmjs || exit 1 //removed this line
package.json file
"devDependencies": {
// other dependencies
"@babel/plugin-transform-optional-chaining": "^7.24.5",
"webpack": "^5.91.0",
"webpack-cli": "^5.1.4",
},
"dependencies": {
//other dependencies
"path-browserify": "^1.0.1",
"uuid": "^3.3.2",
"ws": "^8.17.0"
},
"babel": {
"presets": [
"@babel/env"
],
"plugins": [
"@babel/syntax-dynamic-import",
"@babel/transform-runtime",
"@babel/plugin-transform-optional-chaining" //added this
]
},
webpack.config.js
const path = require("path");
const CleanWebpackPlugin = require("clean-webpack-plugin");
module.exports = {
stats: {
children: true, //added this to get detail error (optional)
},
externals: {
ws: "ws", //added this
},
resolve: {
fallback: {
dgram: false, // Instead of 'empty', use false to provide nothing.
fs: false, // Provide a mock if necessary, or false to provide nothing.
net: false, // Provide a mock if necessary, or false to provide nothing.
tls: false, // Provide a mock if necessary, or false to provide nothing.
crypto: false, // Provide a polyfill or mock.
child_process: false, // Provide a mock if necessary, or false to provide nothing.
path: require.resolve("path-browserify"),
},
},
entry: ["./src/index.js"],
output: {
filename: "tdweb.js",
path: path.resolve(__dirname, "dist"),
library: "tdweb",
libraryTarget: "umd",
umdNamedDefine: true,
globalObject: "this",
},
devServer: {
contentBase: "./dist",
},
plugins: [
// new HtmlWebpackPlugin(),
new CleanWebpackPlugin({}),
//, new UglifyJSPlugin()
],
optimization: {
minimize: false, // <---- disables uglify.
},
module: {
noParse: /td_asmjs\.js$/,
rules: [
{
test: /\.(js|jsx)$/,
exclude: /prebuilt/,
enforce: "pre",
include: [path.resolve(__dirname, "src")],
use: [
{
loader: require.resolve("eslint-loader"),
},
],
},
{
test: /worker\.(js|jsx)$/,
include: [path.resolve(__dirname, "src")],
use: [
{
loader: require.resolve("worker-loader"),
},
],
},
{
test: /\.(js|jsx)$/,
exclude: /prebuilt/,
include: [path.resolve(__dirname, "src")],
use: [
{
loader: require.resolve("babel-loader"),
},
],
},
{
test: /\.(wasm|mem)$/,
include: [path.resolve(__dirname, "src")],
type: "javascript/auto",
use: [
{
loader: require.resolve("file-loader"),
},
],
},
],
},
node: {}, //removed this
performance: {
maxAssetSize: 30000000,
},
};
Since latest version of emsdk doesn't generate .mem file, I removed the related code from worker.js file
worker.js
//import td_asmjs_mem_release from './prebuilt/release/td_asmjs.js.mem'; //removed this liine
// rest of the code
async function loadTdlibAsmjs(onFS) {} //removed the implementation of asm.js
// rest of the code
Since latest version of emsdk doesn't generate .mem file
It wasn't generated, because you removed building of the target td_asmjs.
Newer EMSDK versions wasn't tested, but they may work. If build succeeds, then it is likely that tdweb will work.