diff --git a/package.json b/package.json index 463d74e50..876a7bf11 100644 --- a/package.json +++ b/package.json @@ -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", @@ -26,6 +30,7 @@ "license": "GPL-3.0", "devDependencies": { "typescript": "latest", + "vite": "^5.4.3", "vitest": "^1.2.2" }, "dependencies": { diff --git a/src/i18n.ts b/src/i18n.ts index 47f55bcc0..36923cd18 100644 --- a/src/i18n.ts +++ b/src/i18n.ts @@ -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' diff --git a/tsconfig.json b/tsconfig.json index 20e449e67..c403225a9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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"], diff --git a/vite.config.js b/vite.config.js new file mode 100644 index 000000000..19b0122b8 --- /dev/null +++ b/vite.config.js @@ -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: { }, + }, + }, + }, +}); \ No newline at end of file