Fork me on GitHub
#announcements
<
2022-08-27
>
timonkot1318:08:12

Hello, I want to present my humble template https://github.com/timonkot131/clojurescript-screeps-webpack. It uses webpack with babel for bundling instead of the Closure's advanced optimizations. I have seen some of the Screeps projects on github, but all of them use optimizations. These optimizations are really nice when you are deploying your code to prod, so your script loads pretty fast, but this is not the case for deploying for Screeps, because it doesn't produce understandable error messages due to massive minifications. So I decided to create this project to resolve this issue. The template doesn't do a lot of stuff, it just compiles the code via https://github.com/thheller/shadow-cljs and bundles it via https://github.com/webpack/webpack with https://webpack.js.org/loaders/babel-loader/, thus compiled code can be executed in node 8 environment on screeps server.

😎 1
p-himik18:08:59

> it doesn't produce understandable error messages due to massive minifications Is there no way to make Screeps use source maps?

timonkot1318:08:02

shadow-cljs doc says what this is possible https://shadow-cljs.github.io/docs/UsersGuide.html#compiler-options. I will check this out to see if this will work

MegaMatt19:08:15

I think i’ve been able to get good node stack traces with a combination of the compiler options and the npm package source-map-support

timonkot1320:08:30

I think source-map support is a good feature to have, thus I created an issue for it. I think we may continue the discussion about this topic there https://github.com/timonkot131/clojurescript-screeps-webpack/issues/1. @U02SD8PATK2 So how do you implement it? Can you show your config or leave a link to a project?

MegaMatt01:08:53

I don't any longer. it was in a now abandoned project. but if i recall correctly in the entry file i just required it like so.

(ns some.ns
  (:require ["source-map-support/register"]))
I was using deps.edn and. my build config set
:optimizations :simple
:target        :nodejs
:bundle-cmd {:default ["npx" "webpack" "./out/main.js" "-c" "./webpack.config.js"]}
and my webpack is
const path = require('path');

module.exports = {
  mode: 'production',
  entry: './out/main.js',
  target: 'node',
  // devtool: 'source-map',
  output: {
    path: path.resolve(__dirname, 'deploy'),
    filename: 'main.js',
  },
};
I don't remember if there was anything else involved as this was quite a while ago. I was deploying things to a lambda.

timonkot1312:08:48

Actually, I have ended up with the same solution as you, but with (.install (js/require source-map-support)). It works fine with nodejs, but in the screeps environment, it shows this error

Error: Unknown module 'path'
    at Object.requireFn (<isolated-vm>:20840:23)
    at Object.path (main:26726:18)
    at __webpack_require__ (main:26750:41)
    at Object../node_modules/source-map-support/source-map-support.js (main:22859:12)
It looks like the library uses the "path" module, which is probably constrained by devs. I tried your version, but the error is keeping the same, anyway thanks for the answer. I feel that the possible workaround may be the retrieveSourceMap callback: https://github.com/evanw/node-source-map-support#options

timonkot1316:08:38

@U2FRKM4TW After all, I think this is possible, You just need to consume it via https://github.com/mozilla/source-map and implement error mapping. Like here https://stackoverflow.com/questions/51035699/screeps-how-do-i-set-up-source-map-using-typescript-and-webpack

👍 1