Skip to content

Commit

Permalink
fix: include type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
wkillerud committed Aug 9, 2024
1 parent b2ce8df commit 9cb597b
Show file tree
Hide file tree
Showing 17 changed files with 927 additions and 867 deletions.
22 changes: 9 additions & 13 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,24 @@ on:
- next

jobs:
test:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
- uses: actions/setup-node@v4
with:
node-version: 20

- name: Install dependencies
run: npm install
- run: npm install

- name: Lint files
run: npm run lint
- run: npm run lint

- name: Run tests
run: npm run test
- run: npm run types

- name: Run semantic release
run: npx semantic-release
- run: npm test

- run: npx semantic-release
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- next

jobs:
build:
test:
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
Expand All @@ -19,13 +19,14 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- run: npm install

- run: npm run lint

- run: npm run types

- run: npm test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ node_modules
*.iml
*.log
npm-debug.log*
types/
220 changes: 112 additions & 108 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,38 @@ WebPack [Eik](https://eik.dev/) plugin to support the use of import maps to map
## Installation

```bash
$ npm install @eik/webpack-plugin
npm install @eik/webpack-plugin
```

## Usage

```js
export default {
experiments: {
outputModule: true,
},
entry: '/src/input.js',
mode: 'production',
output: {
environment: {
module: true,
},
filename: 'bundle.js',
path: '/out/',
},
module: {
rules: [
{
test: /\.js$/,
use: {
loader: '@eik/webpack-plugin',
options: {
path: '/path/to/eik-json-folder'
},
},
},
],
},
experiments: {
outputModule: true,
},
entry: "/src/input.js",
mode: "production",
output: {
environment: {
module: true,
},
filename: "bundle.js",
path: "/out/",
},
module: {
rules: [
{
test: /\.js$/,
use: {
loader: "@eik/webpack-plugin",
options: {
path: "/path/to/eik-json-folder",
},
},
},
],
},
};
```

Expand All @@ -55,66 +55,68 @@ The path to the location of an `eik.json` file can be specified with the `path`

```js
export default {
//...
module: {
rules: [
{
test: /\.js$/,
use: {
loader: '@eik/webpack-plugin',
options: {
path: '/path/to/eik-json-folder'
},
},
},
],
},
//...
module: {
rules: [
{
test: /\.js$/,
use: {
loader: "@eik/webpack-plugin",
options: {
path: "/path/to/eik-json-folder",
},
},
},
],
},
};
```

The plugin can also be told which URLs to load import maps from directly using the `urls` option.

```js
export default {
//...
module: {
rules: [
{
test: /\.js$/,
use: {
loader: '@eik/webpack-plugin',
options: {
urls: ['http://myserver/import-map']
},
},
},
],
},
//...
module: {
rules: [
{
test: /\.js$/,
use: {
loader: "@eik/webpack-plugin",
options: {
urls: ["http://myserver/import-map"],
},
},
},
],
},
};
```

Additionally, individual mappings can be specified using the `maps` option.

```js
export default {
//...
module: {
rules: [
{
test: /\.js$/,
use: {
loader: '@eik/webpack-plugin',
options: {
maps: [{
imports: {
"lit-element": "https://cdn.eik.dev/lit-element/v2",
}
}],
},
},
},
],
},
//...
module: {
rules: [
{
test: /\.js$/,
use: {
loader: "@eik/webpack-plugin",
options: {
maps: [
{
imports: {
"lit-element": "https://cdn.eik.dev/lit-element/v2",
},
},
],
},
},
},
],
},
};
```

Expand All @@ -124,34 +126,36 @@ ie. in the following example

```js
export default {
//...
module: {
rules: [
{
test: /\.js$/,
use: {
loader: '@eik/webpack-plugin',
options: {
path: '/path/to/eik-json-folder',
urls: ['http://myserver/import-map'],
maps: [{
imports: {
"lit-element": "https://cdn.eik.dev/lit-element/v2",
}
}],
},
},
},
],
},
//...
module: {
rules: [
{
test: /\.js$/,
use: {
loader: "@eik/webpack-plugin",
options: {
path: "/path/to/eik-json-folder",
urls: ["http://myserver/import-map"],
maps: [
{
imports: {
"lit-element": "https://cdn.eik.dev/lit-element/v2",
},
},
],
},
},
},
],
},
};
```

Any import map URLs in `eik.json` will be loaded first, then merged with (and overridden if necessary by) the result of fetching from `http://myserver/import-map` before finally being merged with (and overriden if necessary by) specific mappings defined in `maps`. (In this case `lit-element`)

### Plugin result

Bundles will have bare imports mapped to absolute URLs.
Bundles will have bare imports mapped to absolute URLs.

Ie. Something like this...

Expand All @@ -169,29 +173,29 @@ import { LitElement, html, css } from "https://cdn.eik.dev/lit-element/v2";

This plugin takes the following options:

| option | default | type | required | details |
| ------- | -------------- | -------- | -------- | ----------------------------------------------------------- |
| path | `cwd/eik.json` | `string` | `false` | Path to eik.json file. |
| urls | `[]` | `array` | `false` | Array of import map URLs to fetch from. |
| maps | `[]` | `array` | `false` | Array of import map as objects. |
| option | default | type | required | details |
| ------ | -------------- | -------- | -------- | --------------------------------------- |
| path | `cwd/eik.json` | `string` | `false` | Path to eik.json file. |
| urls | `[]` | `array` | `false` | Array of import map URLs to fetch from. |
| maps | `[]` | `array` | `false` | Array of import map as objects. |

## Note on ESM with WebPack

This plugin will only apply import maps to ESM modules. Due to this its more or less given that the source of your build must be ESM and that your build output is ESM. WebPack does __not__ by default output ESM so this needs to be configured.
This plugin will only apply import maps to ESM modules. Due to this its more or less given that the source of your build must be ESM and that your build output is ESM. WebPack does **not** by default output ESM so this needs to be configured.

You enable ESM output in WebPack as follows ([reference](https://webpack.js.org/configuration/output/#outputmodule)):

```js
export default {
//...
experiments: {
outputModule: true,
},
output: {
environment: {
module: true,
},
},
//...
experiments: {
outputModule: true,
},
output: {
environment: {
module: true,
},
},
};
```

Expand Down
7 changes: 6 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import config from "@eik/eslint-config";

export default config;
export default [
...config,
{
ignores: ["tap-snapshots/*", "node_modules/*", "fixtures/*"],
},
];
Loading

0 comments on commit 9cb597b

Please sign in to comment.