Skip to content

Commit

Permalink
esm and cjs
Browse files Browse the repository at this point in the history
  • Loading branch information
Tommytrg committed Sep 10, 2024
1 parent f694495 commit 1bb2fab
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@
"name": "witnet-radon-js",
"version": "1.0.0",
"description": "",
"main": "dist/src/index.js",
"main": "dist/witnet-radon-js.cjs.js",
"module": "dist/witnet-radon-js.es.js",
"types": "dist/src/index.d.ts",
"type": "module",
"files": [
"dist/**/*"
],
"exports": {
".": "./dist/src/index.js"
".": {
"import": "./dist/my-library.es.js",
"require": "./dist/my-library.cjs.js"
}
},
"scripts": {
"build": "tsc -p tsconfig.build.json",
"build": "vite build",
"lint": "prettier --write '{src,test}/**/*.{t,j}s'",
"lint:check": "prettier --check '{src,test}/**/*.{t,j}s'",
"test": "vitest",
Expand All @@ -26,6 +30,7 @@
"license": "GPL-3.0",
"devDependencies": {
"typescript": "latest",
"vite": "^5.4.3",
"vitest": "^1.2.2"
},
"dependencies": {
Expand Down
6 changes: 2 additions & 4 deletions src/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import rosetta, { Rosetta } from 'rosetta'
import { createRequire } from 'module'
const require = createRequire(import.meta.url)
const en = require('./locales/en.json')
const es = require('./locales/es.json')
import en from './locales/en.json'
import es from './locales/es.json'

export type Locale = 'en' | 'es'

Expand Down
7 changes: 6 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@
"strictNullChecks": true,
"strictPropertyInitialization": true,
"target": "ESNext",
"typeRoots": ["./node_modules/@types", "@types"],
"typeRoots": [
"./node_modules/@types",
"./node_modules/@microsoft",
"./node_modules"
],
"types": ["vitest/globals"]
},
"include": ["./**/*.ts"],
"exclude": ["node_modules", "dist"],
Expand Down
18 changes: 18 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { defineConfig } from 'vite';
import { resolve } from 'path';

export default defineConfig({
build: {
lib: {
entry: resolve(__dirname, 'src/index.ts'),
name: 'witnet-radon-js',
fileName: (format) => `witnet-radon-js.${format}.js`,
formats: ['es', 'cjs'],
},
rollupOptions: {
output: {
globals: { },
},
},
},
});

0 comments on commit 1bb2fab

Please sign in to comment.