GithubHelp home page GithubHelp logo

Comments (10)

gzm0 avatar gzm0 commented on June 10, 2024 1

Why is the Compile scope not needed for withModuleKind, but is needed for withMinify?

Because of how we configure the fullLink config:

scalaJSLinkerConfig in fullOptJS ~= { prevConfig =>
val useClosure = prevConfig.moduleKind != ModuleKind.ESModule
prevConfig
.withSemantics(_.optimized)
.withClosureCompiler(useClosure)
.withMinify(true) // ignored if we actually use Closure
.withCheckIR(true) // for safety, fullOpt is slow anyways.
},

You'll notice this is scoped in both the configuration and the task. I guess at some point in the past, we decided (explicitly or implicitly) it's more important to be able to re-configure configs easily then re-configure fast v.s. full defaults easily. (I'm making the assumption here that sbt axis are not hierarchical but I believe this is the case).

I can prepare PR for that if desired.

Always appreciated. Please do note that the commit structure of that repo is a bit odd: The commits correspond to steps. So you essentially need to rewrite its entire history to update it.

Would this also be in scope of the Basic Tutorial?

IMO no. The basic tutorial is officially "old" (as you can see from the Tutorial Overview). The Scala.js and Vite tutorial does perform JS minification (or more precisely Vite's production build does).

from scala-js.

sjrd avatar sjrd commented on June 10, 2024 1

First, always use fastLinkJS/fullLinkJS when configuring, even if you use the Opt tasks in the end.

Second, just fastLinkJS / never does anything. It's always Compile / fastLinkJS /.

from scala-js.

gzm0 avatar gzm0 commented on June 10, 2024

Yes. Also, the config is documented in source:
linker-interface/shared/src/main/scala/org/scalajs/linker/interface/StandardConfig.scala

Seems like the scaladoc comments are not in the right place. We should obviously fix that.

from scala-js.

OndrejSpanel avatar OndrejSpanel commented on June 10, 2024

I do not think the GCC stops being used unless I use scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.ESModule) }. With CommonJSModule I always see [info] Closure: 0 error(s), 0 warning(s) and the filesize is exactly what is was before.

from scala-js.

gzm0 avatar gzm0 commented on June 10, 2024

Ah, right. I think you need to scope it in the config as well:

Compile / fullLinkJS / scalajsLinkerConfig

from scala-js.

OndrejSpanel avatar OndrejSpanel commented on June 10, 2024

Confirmed, with Compile / fullLinkJS I can choose the minifier.

Why is the Compile scope not needed for withModuleKind, but is needed for withMinify? How about withOptimizer - does it need the Compile scope as well?

I am checking some other basic documentation and tutorials. If you clone https://github.com/scala-js/scalajs-tutorial, it uses ancient versions of sbt and Scala.js, IntelliJ is unable to import the project. I can prepare PR for that if desired.

A bit related: it seems the minifier assumes some other JS minification will be done later in the pipeline, at least its ScalaDoc says so. Would this also be in scope of the Basic Tutorial?

from scala-js.

OndrejSpanel avatar OndrejSpanel commented on June 10, 2024

Thanks for the explanation.

How about withOptimizer - does it need the Compile scope as well?

Still unclear about withOptimizer(false) - should it be used from Compile / fastOptJS or just fastOptJS?

from scala-js.

OndrejSpanel avatar OndrejSpanel commented on June 10, 2024

Explanation is good, but the main point of this issue is to improve documentation so that the explanation here is not necessary.

Besides the links I have provided, some related documentation seems to be present in https://www.scala-js.org/doc/project/building.html as well. However I doubt I want to have this in my SBT:

scalaJSLinkerConfig ~= { _.withOptimizer(false) }

I would almost certanly want to disable optimizer for fastOpt only, because that is where I expect to do my debugging.

from scala-js.

OndrejSpanel avatar OndrejSpanel commented on June 10, 2024

First, always use fastLinkJS/fullLinkJS when configuring

I have tried it now with the Scala.js Tutorial project.

This affects fastOptJS output:

Compile / fastOptJS / scalaJSLinkerConfig ~= (_.withOptimizer(false))
Compile / fastLinkJS / scalaJSLinkerConfig ~= (_.withOptimizer(false))
fastOptJS / scalaJSLinkerConfig ~= (_.withOptimizer(false))

This does not:

fastLinkJS / scalaJSLinkerConfig ~= (_.withOptimizer(false))

from scala-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.