You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: compile runtime/shell to JS before publishing
Ship compiled JavaScript + .d.ts declarations instead of raw TypeScript
source. This allows consuming apps to also pre-compile their TypeScript
and use tsc-alias to resolve arbitrary paths (such as @src).
And so that `npm run dev` can also resolve these paths, we add
tsconfig-paths-webpack-plugin to webpack.config.dev.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@@ -137,6 +138,12 @@ With the exception of any custom scripts, replace the `scripts` section of your
137
138
},
138
139
```
139
140
141
+
The `build` script compiles TypeScript to JavaScript and uses `tsc-alias` to rewrite `@src` path aliases to relative paths. You'll need to install `tsc-alias` as a dev dependency:
142
+
143
+
```sh
144
+
npm install --save-dev tsc-alias
145
+
```
146
+
140
147
- Replace `YOUR_PORT` with the desired port, of course.
141
148
- Replace `YOUR_APP_NAME` with the basename used on your site.config, not doing this will result in only the root route working.
142
149
- Note that `fedx-scripts` no longer exists, and has been replaced with `openedx`.
@@ -150,21 +157,24 @@ Other package.json edits
150
157
151
158
- Change the author to "Open edX"
152
159
153
-
main
154
-
----
160
+
main and types
161
+
--------------
162
+
163
+
Point to the compiled output:
155
164
156
165
```json
157
-
"main": "src/index.ts",
166
+
"main": "dist/index.js",
167
+
"types": "dist/index.d.ts",
158
168
```
159
169
160
170
files
161
171
-----
162
172
163
-
This is a buildless library, so we package files in `src`:
173
+
Package the compiled output in `dist`:
164
174
165
175
```json
166
176
"files": [
167
-
"/src"
177
+
"/dist"
168
178
],
169
179
```
170
180
@@ -196,15 +206,10 @@ Finally, make sure the following fields are set properly:
196
206
Clean up .npmignore
197
207
===================
198
208
199
-
This is what should be in the repo's `.npmignore`. No more, no less:
209
+
Since we use the `files` field in `package.json` to whitelist only `/dist`, the `.npmignore` file is largely unnecessary. You can delete it or keep a minimal version:
200
210
201
211
```
202
-
__mocks__
203
212
node_modules
204
-
*.test.js
205
-
*.test.jsx
206
-
*.test.ts
207
-
*.test.tsx
208
213
```
209
214
210
215
Clean up .gitignore
@@ -259,8 +264,12 @@ Create a `tsconfig.json` file and add the following contents to it:
@@ -275,6 +284,57 @@ Create a `tsconfig.json` file and add the following contents to it:
275
284
276
285
This assumes you have a `src` folder and your build goes in `dist`, which is the best practice.
277
286
287
+
The `@src` path alias
288
+
---------------------
289
+
290
+
The `paths` configuration above sets up the `@src` alias, which allows you to import from your app's `src` directory using `@src/...` instead of relative paths. For example:
For this to work, the app must define its own `@src` path mapping in `tsconfig.json`. **tsc-alias** will then rewrite `@src` imports to relative paths during the build step, so the compiled JavaScript has proper paths.
301
+
302
+
Add a tsconfig.build.json file
303
+
------------------------------
304
+
305
+
Create a `tsconfig.build.json` file for compiling your app before publishing:
306
+
307
+
```json
308
+
{
309
+
"extends": "./tsconfig.json",
310
+
"compilerOptions": {
311
+
"rootDir": "src",
312
+
"outDir": "dist",
313
+
"noEmit": false,
314
+
"declaration": true,
315
+
"declarationMap": false,
316
+
"sourceMap": false
317
+
},
318
+
"include": [
319
+
"src/**/*"
320
+
],
321
+
"exclude": [
322
+
"src/**/*.test.ts",
323
+
"src/**/*.test.tsx",
324
+
"src/**/*.spec.ts",
325
+
"src/**/*.spec.tsx",
326
+
"src/__mocks__/**/*",
327
+
"src/setupTest.js"
328
+
]
329
+
}
330
+
```
331
+
332
+
This config:
333
+
- Extends your main `tsconfig.json`
334
+
- Outputs compiled JavaScript and type declarations to `dist/`
335
+
- Excludes test files and mocks from the published package
336
+
- Disables source maps for smaller package size
337
+
278
338
279
339
Edit jest.config.js
280
340
===================
@@ -789,7 +849,7 @@ Create a new `app.scss` file at the top of your application. It's responsible f
@@ -876,17 +936,18 @@ First, rename `src/plugin-slots`, if it exists, to `src/slots`. Modify imports
876
936
Next, the frontend-base equivalent to `<PluginSlot />` is `<Slot />`, and has a different API. This includes a change in the slot ID, according to the [new slot naming ADR](../decisions/0009-slot-naming-and-lifecycle.rst) in this repository. Rename them accordingly. You can refer to the `src/shell/dev` in this repository for examples.
877
937
878
938
879
-
Remove build step from CI
880
-
=========================
939
+
Update build step in CI
940
+
=======================
881
941
882
-
In `.github/workflow/ci.yml`, remove the build step.
942
+
In `.github/workflow/ci.yml`, ensure the build step runs the TypeScript compilation:
883
943
884
-
```diff
944
+
```yaml
885
945
- name: Test
886
946
run: npm run test
887
-
- - name: Build
888
-
- run: npm run build
947
+
- name: Build
948
+
run: npm run build
889
949
- name: i18n_extract
890
950
run: npm run i18n_extract
891
951
```
892
-
```
952
+
953
+
The build step compiles TypeScript to JavaScript and rewrites `@src` path aliases using `tsc-alias`.
0 commit comments