Skip to content

Commit

Permalink
Merge pull request #9 from mapbox/1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mbullington committed Apr 1, 2022
2 parents ed75b23 + 2039608 commit a9e2ea2
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v1.2.1

- Allow for `"platform": "node"` to be specified and not overridden.

# v1.2.0

- If `globalName` is specified in `typehead.config.js`, then a fourth IIFE ("CDN") build will be created with that name.
Expand Down
34 changes: 30 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,30 @@ In your `package.json`:

Typehead will not check types or generate declaration files. While this seems initially counter-intuitive, this operation is costly and usually covered by IDE tools (VSCode) and CI (using `tsc`).

We recommend setting this up with `npm install --save-dev dts-bundle-generator`.
We recommend setting this up with `tsc`, which is included with TypeScript.

Here's an example in `package.json` that builds types before publishing to NPM:
Here's an example that builds types before publishing to NPM:

`tsconfig.types.json`:

```json
{
"extends": "./tsconfig.json",
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "./dist"
},
"include": ["src/*", "src/**/*"]
}
```

`package.json`:

```json
{
"scripts": {
"types": "dts-bundle-generator -o dist/index.d.ts src/index.ts",
"types": "tsc -p tsconfig.types.json",
"prepare": "npm run types && npm run build"
}
}
Expand All @@ -48,11 +64,21 @@ This behavior is configurable ([see below](#Customization)).
- A production CSM build `index.js` that is minified.
- A production ESM build `index-esm.js` that is not minified.

### Global name

If `globalName` is specified in [customization](#customization), then a fourth build will be created with that name.

- A production IIFE build `{globalName}.js` that is minified and includes all dependencies statically.

The IIFE build is suitable for distribution on CDNs.
The IIFE build is suitable for distribution on CDNs and [UNPKG](https://unpkg.com/).

`package.json`:

```
{
"unpkg": "dist/{globalName}.js"
}
```

## Serve

Expand Down
16 changes: 16 additions & 0 deletions example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"module": "esnext",
"target": "ES2020",
// This is needed since we use both 'esnext' and 'node' module resolution.
// https://www.typescriptlang.org/docs/handbook/module-resolution.html#module-resolution-strategies
"moduleResolution": "node",
"lib": ["dom", "ES2020", "ESNext"],
// Treat JSX as React.
"jsx": "react",
// Make sure CommonJS modules are read correctly.
"esModuleInterop": true,
// Significant perf increase by skipping checking .d.ts files.
"skipLibCheck": true
}
}
9 changes: 9 additions & 0 deletions example/tsconfig.types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "./dist"
},
"include": ["src/*", "src/**/*"]
}
3 changes: 3 additions & 0 deletions example/types.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

../node_modules/.bin/tsc -p tsconfig.types.json
8 changes: 7 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mapbox/typehead",
"version": "1.2.0",
"version": "1.2.1",
"description": "Refreshingly simple CLI for TypeScript packages.",
"main": "index.mjs",
"type": "module",
Expand Down Expand Up @@ -49,7 +49,8 @@
"eslint-config-prettier": "^8.3.0",
"lint-staged": "^11.1.2",
"lodash": "^4.17.21",
"prettier": "^2.3.2"
"prettier": "^2.3.2",
"typescript": "^4.6.3"
},
"engines": {
"node": ">=14.17.6"
Expand Down
10 changes: 8 additions & 2 deletions src/util/getEsbuildConfig.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,21 @@ export async function getEsbuildConfig() {
console.debug('Skipping typehead config, using defaults.');
}

return deepmerge(configFile, {
const config = deepmerge(configFile, {
sourcemap: true,
bundle: true,
platform: 'neutral',
plugins: [
// Automatically rewrite Lodash statements.
lodashPlugin({
filter: IS_RELATIVE_AND_JS,
}),
],
});

// Only set platform if not set by the configuration.
if (!config.platform) {
config.platform = 'neutral';
}

return config;
}

0 comments on commit a9e2ea2

Please sign in to comment.