Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jun 05 19:53
    ptrdom opened #428
  • Jun 02 17:17
    ptrdom commented #427
  • Jun 02 17:09
    ptrdom commented #427
  • Jun 02 09:22
    sjrd commented #427
  • May 31 19:21
    ptrdom commented #427
  • May 31 19:13
    sjrd commented #427
  • May 31 15:08
    viktor-podzigun closed #197
  • May 31 15:03
    viktor-podzigun closed #198
  • May 31 15:03
    viktor-podzigun commented #198
  • May 27 19:52
    armanbilge commented #197
  • May 26 17:24
    ptrdom opened #427
  • May 24 11:11
    easel removed as member
  • May 21 10:26
    ptrdom commented #420
  • May 21 09:30
    ptrdom synchronize #420
  • May 21 08:48
    ptrdom synchronize #420
  • May 21 08:44
    ptrdom synchronize #420
  • May 21 08:12
    ptrdom synchronize #420
  • May 21 08:00
    ptrdom synchronize #420
  • May 20 18:35
    julienrf closed #368
  • May 20 18:15
    ptrdom commented #368
Eric K Richardson
@ekrich
@kahliburke :point_up:
Kahli Burke
@kahliburke
@ekrich Thanks for the reference, in this case I'm not really concerned with the way that the code is split. I'm happy with the external JS libraries being bundled to one file and the ScalaJS output to another. It's just the source map doesn't work out of the box, I'd need to add server routes for http://host/src/* for the browser to resolve them. Which I'm somewhat OK doing as it's only for development purposes, I can disable that route for production. But since it worked "out of the box" previously before I switched to scalajs-bundler, I thought I'd see if there's a better solution first.
I will check out snowpack use too, although it would be nice to stick with something more SBT oriented.
Eric K Richardson
@ekrich
Good luck, just wanted to let you know as code splitting is really cool to have as an option.
Mark de Jong
@Fristi

Is there a write up about reducing the bundle size? Quickly scanning through this channel it's kind of a duplicate quesetion being asked... I've seen some docs Bundling mode, but I think there is more to it I think:

  • Specific bundles which can be identified with maybe https://www.npmjs.com/package/webpack-bundle-analyzer ? I tried it, but couldn't make it work yet
  • What scalajs libs contribute to a large size?
  • Does tree shaking work? And what would be needed to enable it?
  • Does code splitting work with this plugin? And what would be needed to enable it?

At the moment with fullOptJS::webpack my bundle size is 7,2 mb (using scalajs-react, circe, endpoints4s, droste (local build)).. I guess there are transitive dependencies and maybe code which is not being used?

Julien Richard-Foy
@julienrf
@Fristi The Scala.js optimizer removes unused Scala code. Webpack won’t include dependencies that are not imported. So, the only thing I can think of is to make sure that your NPM dependencies are also minified (remember that fullOptJS does minify the output of Scala.js, but it doesn’t process your dependencies).
Julien Richard-Foy
@julienrf
@Fristi what is the size of the -opt.js file produced by Scala.js?
Mark de Jong
@Fristi
@julienrf notistack-frontend-opt.js is 823kb
Julien Richard-Foy
@julienrf
Ah, it seems that your NPM dependencies bring the remaining 6 Mo. Make sure to compress them. See https://webpack.js.org/configuration/optimization/#optimizationminimize
Mark de Jong
@Fristi
Thanks! :) It seems the most of the bundle size is ruled by tailwind.. all css is bundled. They are using purgecss to clean it up, there is a webpack plugin for that. Figuring out how to configure it in conjuction with scala js
Mark de Jong
@Fristi
Fixed it, if someone in any case want the same thing with purgecss:
const glob = require('glob');
const purgecss = require('@fullhuman/postcss-purgecss')

module.exports = {
  plugins: [
    require('postcss-import'),
    require('tailwindcss'),
    require('autoprefixer'),
    purgecss({
        content: glob.sync('../../../../**/*.scala'),
        defaultExtractor: content => {
            const regex = /className := "(.*?)"/g;
            const result = [...content.matchAll(regex)].map(match => match[1]) || [];
            return result.map(x => x.split(' ')).flat();
        }
    })
  ]
};
Mark de Jong
@Fristi
The downside, is that it will not work when you use dynamic className inside your scala code
Mathieu
@mathieuleclaire
Hi, I asked a question in the issues section on github, but perhap's it was not the appropriate place. Here is my issue (https://github.com/scalacenter/scalajs-bundler/issues/194#issuecomment-773490925). It should be something trivial to achieve with scalajs-bundler I guess.
Julien Richard-Foy
@julienrf
Do you know how this problem would be solved in plain JS+Webpack?
Mathieu
@mathieuleclaire
This seems to be the way to solve it ij js+webpack: https://github.com/ajaxorg/ace/blob/master/demo/webpack/demo.js#L12. Note that I do not need the "dynamic" mode loading. I basically need one theme and 2 or 3 language mode. A webpack config is set in the demo repository: "https://github.com/ajaxorg/ace/tree/master/demo/webpack/webpack.config.js"
Julien Richard-Foy
@julienrf
I guess you tried the solution I suggested in my last comment? With @JSImport
Mathieu
@mathieuleclaire
This solution means I need to choose in my facade what theme or mode I want. Or I need to JsImport all modes and themes provided by ace ?
Julien Richard-Foy
@julienrf
Ah sorry, I thought you didn’t need dynamic module loading
But yes, one solution would be to bundle all the possible modes and themes, but it might be impractical… So, maybe you want to resort to dynamic module loading.
Mathieu
@mathieuleclaire
Does it mean, that all js mode would be packed in my js file ?
It could possibly be huge
And you are right, I don't need dynamic loading, just a couple of identified modes and one or two themes
Julien Richard-Foy
@julienrf
I don’t follow. On the one hand I understand that you say that you only need a couple of modes and themes, and on the other hand I understand that you say that the resulting bundle could be huge.
Mathieu
@mathieuleclaire
If I use a the dynamic strategy I mean.
Julien Richard-Foy
@julienrf
With dynamic module loading, the dynamically loaded modules would not be part of the bundle, so the bundle wouldn’t be huge
But I’ve never tried to do that in Scala.js, so I can’t really help :-/
Mathieu
@mathieuleclaire
OK, but the dynamic loaded module is used if you want to have all syntax highlighting potentially for all languages, which is not my case.
I tried with extra JSImport but the output js remains the same
but I guess my syntax is wrong
Julien Richard-Foy
@julienrf
Do you also refer to the JSImported module in your program entry point?
Mathieu
@mathieuleclaire
No. And that was the key.
Mathieu
@mathieuleclaire
So this works: in my facade:
@js.native
@JSImport("ace-builds/src-noconflict/mode-scala.js", JSImport.Namespace)
object scalamode extends js.Object
and I need to call scalamode in my program entry point
Is it the regular way to achieve this ?
Julien Richard-Foy
@julienrf
Yes, Webpack only includes modules that are “used”, in the resulting bundle
Do you mind updating the related issue?
Mathieu
@mathieuleclaire
Yes, sure. Thanks for helping !
Julien Richard-Foy
@julienrf
Thanks for your patience!
Mathieu
@mathieuleclaire
Same compliment for you !
the version currently used for webpack 4 has several deprecations
[info] Updating NPM dependencies
[error] npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
[error] npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
[error] npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
[error] npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
[error] npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
[error] npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
Russ White
@russwyte

I tried this:

   npmDevDependencies in Compile ++= Seq(
      "source-map-loader" -> "2.0.1"
    ),

but that results in this error:

[error] npm ERR! notarget No matching version found for source-map-loader@2.0.1 0.2.3.
Russ White
@russwyte
It looks like version 1.1.3 should work for webpack 4 - but I am not sure I have a good way to specify that.
It seems to me that if that library is already in npmDevDependencies - then that version should be used instead of the hard coded version.
Milan Satala
@msatala
Hi guys, I'm pretty sure it was asked and answered before but I'm not able to find it. Is it possible to use Scala.js 1.3+ module splitting in combination with scalajs-bundler?
Sébastien Doeraene
@sjrd
No, it's not possible yet.
We are proposing a project to implement that at GSoC this year (assuming our org gets accepted).
Milan Satala
@msatala
@sjrd Thank you for answering.
On a project where we don't have scalajs-bundler nor module splitting yet we will go the module splitting route since we deploy often and the JS output is quite large.