Skip to content

Commit 5e5551c

Browse files
committed
Init
1 parent 8bed6f9 commit 5e5551c

File tree

10 files changed

+3573
-2
lines changed

10 files changed

+3573
-2
lines changed

.github/workflows/CI.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- name: Setup Node.js
14+
uses: actions/setup-node@v4
15+
with:
16+
node-version: 20
17+
cache: yarn
18+
- run: yarn install
19+
- run: yarn run:webpack
20+
- run: yarn run:esbuild

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@
1111

1212
#!.yarn/cache
1313
.pnp.*
14+
node_modules
15+
dist

.yarn/releases/yarn-4.1.0.cjs

Lines changed: 893 additions & 0 deletions
Large diffs are not rendered by default.

.yarnrc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
nodeLinker: node-modules
2+
3+
yarnPath: .yarn/releases/yarn-4.1.0.cjs

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,19 @@
1-
# use-napi-rs-packages-with-bundlers
1+
# Use bundlers to bundle NAPI-RS package
2+
3+
## Getting started
4+
5+
```bash
6+
yarn install
7+
```
8+
9+
## webpack
10+
11+
Build and run the webpack example:
12+
13+
`yarn run:webpack`
14+
15+
## esbuild
16+
17+
Build and run the esbuild example:
18+
19+
`yarn run:esbuild`

package.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11
{
22
"name": "use-napi-rs-packages-with-bundlers",
3-
"packageManager": "yarn@4.1.0"
3+
"version": "0.0.0",
4+
"private": true,
5+
"type": "module",
6+
"packageManager": "yarn@4.1.0",
7+
"devDependencies": {
8+
"@node-rs/argon2": "^1.7.2",
9+
"@types/webpack": "^5.28.5",
10+
"esbuild": "^0.20.1",
11+
"node-loader": "^2.0.0",
12+
"rollup": "^4.12.0",
13+
"webpack": "^5.90.3",
14+
"webpack-cli": "^5.1.4"
15+
},
16+
"scripts": {
17+
"run:esbuild": "yarn esbuild --bundle src/index.js --outfile=dist/esbuild.cjs --platform=node --loader:.node=copy --format=cjs && node dist/esbuild.cjs",
18+
"run:webpack": "webpack --mode=production && node dist/bundled.cjs"
19+
}
420
}

renovate.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
3+
"extends": [
4+
"config:base",
5+
"group:allNonMajor",
6+
":preserveSemverRanges",
7+
":disablePeerDependencies"
8+
],
9+
"labels": ["dependencies"],
10+
"commitMessagePrefix": "chore: ",
11+
"commitMessageAction": "bump up",
12+
"commitMessageTopic": "{{depName}} version",
13+
"ignoreDeps": []
14+
}

src/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { hash } from '@node-rs/argon2'
2+
3+
async function main() {
4+
const hashed = await hash('password', {
5+
timeCost: 3
6+
})
7+
console.info(hashed)
8+
}
9+
10+
main().catch((err) => {
11+
console.error(err)
12+
})

webpack.config.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { join } from 'node:path'
2+
import { fileURLToPath } from 'node:url'
3+
4+
const __dirname = join(fileURLToPath(import.meta.url), '..')
5+
6+
/**
7+
* @returns {import('webpack').Configuration}
8+
*/
9+
export default () => ({
10+
entry: './src/index.js',
11+
target: 'node',
12+
output: {
13+
filename: 'bundled.cjs',
14+
path: join(__dirname, 'dist'),
15+
chunkFormat: 'commonjs'
16+
},
17+
module: {
18+
rules: [
19+
{
20+
test: /\.node$/,
21+
loader: 'node-loader'
22+
}
23+
]
24+
},
25+
stats: 'errors-only',
26+
})

0 commit comments

Comments
 (0)