knockout / tko

🥊 Technical Knockout – The Monorepo for Knockout.js (4.0+)
http://www.tko.io
Other
275 stars 34 forks source link

How to build and import TKO-beta as a bundled library. #178

Open Mikhail-Ananev opened 2 years ago

Mikhail-Ananev commented 2 years ago

Hello. I'm trying to build and import recent TKO-beta version at my TS project built from source (as of npm-hosted version is alpha7). So, I cloned that repo and run "make" (if I understood correctly, the default is make 'all', which uses npx'ed Lerna as packager for individual of packages from the monorepo in packages and calls their builders) command from root of the repo, then I got "builds" folder with 2 folder inside: "knockout" and "reference". Right now i'm struggling to pinpoint/understand the functional difference between these two versions of TKO, and the purpose of the 'reference' build. I'd really appreciate some advice.

Looks like the TKO library should be ready to be imported right from dist directory, but different file depending of used in-project modules. I understood that there are multiple build targets for different types of modules like ECM or commonJS, etc., and while using the build with ECM, i should be using the import ko from "<arbitrary path>/libs/tko/builds/knockout/dist/index.js" build. Please, correct me if i'm wrong. And, may it possibly be connected to https://github.com/knockout/tko/issues/158 ?

Also, if these questions are resolved, may I contribute to a readme for more clearance/updated guide on the build-to-usage pipeline. Right now I'm looking into https://github.com/knockout/tko/issues/134 by which way the build process may be improved. Thank you!

ironkayman commented 2 years ago

Hi! Its just my guess - seems like that these are bundled yarn add @tko/build.reference and yarn add @tko/build.knockout from project readme. Basically, quoting readme:

The Knockout build has some backwards compatibility that is not in the reference build.  See the build differences, here: https://tko.io/3to4

It's available as `@tko/build.knockout`, and over CDN:

is a compatibility-oriented build, while build.reference is canonical TKO 4 beta 1.3 without further compatibilities. I'll look into it.

UPD 1: yeah, builds/reference/package.json: "name": "@tko/build.reference",

UPD 2: calling make from project root builds bundles, builds/reference/index.ts tells about unknown version of TKO, while with importing dist/index.js as ESM, ko.applyBindings does not seem work with components in inlined DOM nodes, at which bindings were applied (for a whole document in my case, by default) Right now I could advice until somebody tells otherwise to build from tags/4.0.0-alpha9 with npm i -> npm run build -> and than use/call import ko from "<...your arbitrary path...>/tko/packages/tko/dist/tko.es6.min.js" as that build works fine as up now for me (i guess). I'll look further into beta* builds.

ironkayman commented 2 years ago

Hi, so working with beta1.3 tag the problem seems to be in some circular deps (my guess):

ECS

Importing with anything like:

import * as ko from "tko/builds/reference/dist/index.js"
import ko from "tko/builds/reference/dist/index.js"
import tko from "tko/builds/reference/dist/index.js"

i'm getting TypeError: Class extends value undefined is not a constructor or null


browser.js

but, calling

import "tko/builds/reference/dist/browser.min.js"
// and then for compatibility
const ko = tko

does the trick

ironkayman commented 2 years ago

Hi! I think this issue can be closed due to https://github.com/knockout/tko/issues/179