Creating one is simple:
- Have a directory that looks something like this:
big-folder/
├── packages/
│ ├── electron-app/
│ │ ├── src/
│ │ └── package.json (requires 'shared-types')
│ ├── chrome-extension/
│ │ ├── src/
│ │ └── package.json (requires 'shared-types')
│ └── shared-types/
│ ├── src/
│ └── package.json (name: 'shared-types')
To initialize shared-types, run the usual:
npm initnpm install --save-dev typescript- Initialize
package.json"name": "big-app-shared-types"(for this example)"main": "dist/index.js""types": "dist/index.d.ts"- This is IMPORTANT. But alsotodo I am not sure what the
.drepresents.
- This is IMPORTANT. But alsotodo I am not sure what the
- Ensure you have
"build": "tsc"as a pair inside of"scripts"withinpackage.json
Then the index.ts within src might look like this:
export * from './shared';That’s all. Populate shared.ts with all the interfaces and enums and constants you want!
From there we go into our electron app’s package.json and include this dependency:
"dependencies": {
...
"big-app-shared-types": "file:../shared-types",
...
}and lastly we run npm install prod-app-shared within the electron app’s directory and all should be set up.
You can import all the stuff with import * as _ from 'big-app-shared-types now.