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
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).
At the bundler level, we add tsconfig-paths-webpack-plugin to Webpack
configuration so that the Typescript aliases can also be used by Webpack
builds without duplicating their definition.
As part of this, unify the tsc builds so that everything ends up in
/dist, and then use more modern export maps to decouple the internal
file structure from the package's API.
Of note, the default tsconfig (not the one used by tools) now uses
`moduleResolution: bundler` to allow for more modern entrypoint
definition.
BREAKING CHANGE: consuming apps need to modify their imports and
configuration accordingly. See the changes in the migration howto for
details.
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This target compiles TypeScript to JavaScript, uses `tsc-alias` to rewrite `@src` path aliases to relative paths, and copies all SCSS files from `src/` into `dist/` preserving directory structure.
159
+
140
160
- Replace `YOUR_PORT` with the desired port, of course.
141
161
- Replace `YOUR_APP_NAME` with the basename used on your site.config, not doing this will result in only the root route working.
142
162
- Note that `fedx-scripts` no longer exists, and has been replaced with `openedx`.
@@ -150,21 +170,32 @@ Other package.json edits
150
170
151
171
- Change the author to "Open edX"
152
172
153
-
main
154
-
----
173
+
exports
174
+
-------
175
+
176
+
DefinethepublicAPIforyourpackage:
155
177
156
178
```json
157
-
"main": "src/index.ts",
179
+
"exports": {
180
+
".": {
181
+
"types": "./dist/index.d.ts",
182
+
"import": "./dist/index.js",
183
+
"default": "./dist/index.js"
184
+
},
185
+
"./app.scss": "./dist/app.scss"
186
+
},
158
187
```
159
188
189
+
The `exports` map decouples your public API from the internal `dist/` directory structure. Consumers import from clean paths (e.g., `@openedx/frontend-app-yourapp/app.scss`) and the map resolves them to the actual files in `dist/`. If your app has SCSS files that downstream site projects need to `@use`, add them as exports as shown above.
190
+
160
191
files
161
192
-----
162
193
163
-
This is a buildless library, so we package files in `src`:
194
+
Package the compiled output in `dist`:
164
195
165
196
```json
166
197
"files": [
167
-
"/src"
198
+
"/dist"
168
199
],
169
200
```
170
201
@@ -175,8 +206,8 @@ This means that the code from the library can be safely tree-shaken by webpack.
175
206
176
207
```json
177
208
"sideEffects": [
178
-
"*.css",
179
-
"*.scss"
209
+
"dist/**/*.css",
210
+
"dist/**/*.scss"
180
211
],
181
212
```
182
213
@@ -196,15 +227,10 @@ Finally, make sure the following fields are set properly:
196
227
Clean up .npmignore
197
228
===================
198
229
199
-
This is what should be in the repo's `.npmignore`. No more, no less:
230
+
Since we use the `files` field in `package.json` to whitelist only `/dist`, the `.npmignore` file is largely unnecessary. You can keep a minimal version:
200
231
201
232
```
202
-
__mocks__
203
233
node_modules
204
-
*.test.js
205
-
*.test.jsx
206
-
*.test.ts
207
-
*.test.tsx
208
234
```
209
235
210
236
Clean up .gitignore
@@ -257,10 +283,14 @@ Create a `tsconfig.json` file and add the following contents to it:
@@ -275,6 +305,53 @@ Create a `tsconfig.json` file and add the following contents to it:
275
305
276
306
This assumes you have a `src` folder and your build goes in `dist`, which is the best practice.
277
307
308
+
The `@src` path alias
309
+
---------------------
310
+
311
+
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.
322
+
323
+
Add a tsconfig.build.json file
324
+
------------------------------
325
+
326
+
Create a `tsconfig.build.json` file for compiling your app before publishing:
327
+
328
+
```json
329
+
{
330
+
"extends": "./tsconfig.json",
331
+
"compilerOptions": {
332
+
"rootDir": "src",
333
+
"outDir": "dist",
334
+
"noEmit": false
335
+
},
336
+
"include": [
337
+
"src/**/*"
338
+
],
339
+
"exclude": [
340
+
"src/**/*.test.ts",
341
+
"src/**/*.test.tsx",
342
+
"src/**/*.spec.ts",
343
+
"src/**/*.spec.tsx",
344
+
"src/__mocks__/**/*",
345
+
"src/setupTest.js"
346
+
]
347
+
}
348
+
```
349
+
350
+
This config:
351
+
- Extends your main `tsconfig.json`
352
+
- Outputs compiled JavaScript and type declarations to `dist/`
353
+
- Excludes test files and mocks from the published package
354
+
278
355
279
356
Edit jest.config.js
280
357
===================
@@ -283,7 +360,7 @@ Replace the import from 'frontend-build' with 'frontend-base'.
@@ -494,14 +571,14 @@ SVGR "ReactComponent" imports have been removed
494
571
We have removed the `@svgr/webpack` loader because it was incompatible with more modern tooling (it requires Babel). As a result, the ability to import SVG files into JS as the `ReactComponent` export no longer works. We know of a total of 5 places where this is happening today in Open edX MFEs - frontend-app-learning and frontend-app-profile use it. Please replace that export with the default URL export and set the URL as the source of an `<img>` tag, rather than using `ReactComponent`. You can see an example of normal SVG imports in `test-site/src/ExamplePage.tsx`.
495
572
496
573
497
-
Import createConfig and getBaseConfig from @openedx/frontend-base/config
574
+
Import createConfig and getBaseConfig from @openedx/frontend-base/tools
In frontend-build, `createConfig` and `getBaseConfig` could be imported from the root package (`@openedx/frontend-build`). They have been moved to a sub-directory to make room for runtime exports from the root package (`@openedx/frontend-base`).
You may have handled this in steps 4 and 5 above (jest.config.js and .eslintrc.js)
@@ -874,19 +951,3 @@ Refactor slots
874
951
First, rename `src/plugin-slots`, if it exists, to `src/slots`. Modify imports and documentation across the codebase accordingly.
875
952
876
953
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
-
878
-
879
-
Remove build step from CI
880
-
=========================
881
-
882
-
In `.github/workflow/ci.yml`, remove the build step.
0 commit comments