Web3.js has a function called encodePacked which should do what you have in mind. I couldn't find any information about it in the official docs, but found it while poking around in the source code. You can call it with web3.utils.encodePacked(...args).
As you'll see from the source code, you can pass it a series of objects in order to specify the types that you intend, e.g.:
web3.utils.encodePacked(
{value: 42, type: 'uint128'},
{value: 'trombone', type: 'string'}
);
'0x0000000000000000000000000000002a74726f6d626f6e65'
Contrast this with the return value of encodeParameters, which is not packed:
web3.eth.abi.encodeParameters(['uint128', 'string'], [42, 'trombone']);
0x000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000874726f6d626f6e65000000000000000000000000000000000000000000000000
web3.utils.soliditySha3with the types for each parameter should be equivalent tokeccak256(abi.encodePacked(...)). – Ismael Oct 02 '21 at 04:12