Skip to content

Commit

Permalink
feat: new builder
Browse files Browse the repository at this point in the history
  • Loading branch information
schummar committed Mar 21, 2022
1 parent 1cf41ce commit 8afaf99
Show file tree
Hide file tree
Showing 8 changed files with 868 additions and 85 deletions.
836 changes: 770 additions & 66 deletions package-lock.json

Large diffs are not rendered by default.

39 changes: 26 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,28 @@
"type": "module",
"sideEffects": false,
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"module": "dist/es/index.js",
"exports": {
".": {
"import": "./dist/esm/index.js",
"import": "./dist/es/index.js",
"require": "./dist/cjs/index.js",
"default": "./dist/esm/index.js"
"default": "./dist/es/index.js"
},
"./react": {
"import": "./dist/esm/react/index.js",
"require": "./dist/cjs/react/index.js",
"default": "./dist/esm/react/index.js"
"import": "./dist/es/react.js",
"require": "./dist/cjs/react.js",
"default": "./dist/es/react.js"
}
},
"types": "dist/types/index.d.ts",
"typesVersions": {
"*": {
"*": [
"dist/types/index.d.ts"
],
"react": [
"dist/types/react/index.d.ts"
]
}
},
"author": {
Expand All @@ -39,21 +50,22 @@
"start": "run-p start:*",
"start:compile": "tsc -p tsconfig-cjs.json --watch",
"start:example": "npm --prefix example start",
"build": "npm-run-all -s build:clean -p build:compile:*",
"build:clean": "rimraf dist/**",
"build:compile:esm": "tsc",
"build:compile:cjs": "tsc -p tsconfig-cjs.json && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
"build": "npm-run-all -s build:clean -p build:compile:* -s build:cjsPackage",
"build:clean": "rimraf \"dist/**/*\"",
"build:compile:js": "vite build",
"build:compile:types": "tsc",
"build:cjsPackage": "echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
"lint": "run-p lint:*",
"lint:prettier": "prettier src -l",
"lint:eslint": "eslint src",
"lint:tsc": "tsc --noEmit",
"lint:tsc": "tsc --noEmit --emitDeclarationOnly false",
"prepublishOnly": "run-s build",
"test": "cd test && ava -v",
"test-watch": "cd test && ava --watch",
"coverage": "nyc --include src --all npm run test"
},
"dependencies": {
"intl-messageformat": "^9.9.2"
"intl-messageformat": "^9.11.4"
},
"peerDependencies": {
"@types/react": ">=16.8.0",
Expand Down Expand Up @@ -84,7 +96,8 @@
"react-dom": "^17.0.2",
"rimraf": "^3.0.2",
"ts-node-dev": "^1.1.8",
"typescript": "^4.4.3"
"typescript": "^4.4.3",
"vite": "^2.8.6"
},
"files": [
"dist",
Expand Down
2 changes: 1 addition & 1 deletion react.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './dist/cjs/react';
export * from './dist/types/react';
16 changes: 15 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
export { mergeDicts } from './mergeDicts';
export { createTranslator } from './translator';
export * from './types';
export type {
CreateTranslatorOptions,
CreateTranslatorResult,
DeepValue,
Dict,
FlatDict,
FlatKeys,
FlattenDict,
GetTranslatorOptions,
MaybePromise,
Merge,
Translator,
TranslatorFn,
Values,
} from './types';
25 changes: 23 additions & 2 deletions src/react/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
export { mergeDicts } from '../mergeDicts';
export * from '../types';
export type {
CreateTranslatorOptions,
CreateTranslatorResult,
DeepValue,
Dict,
FlatDict,
FlatKeys,
FlattenDict,
GetTranslatorOptions,
MaybePromise,
Merge,
Translator,
TranslatorFn,
Values,
} from '../types';
export { TranslationContext, TranslationContextProvider } from './translationContext';
export { createTranslator } from './translator';
export * from './types';
export type {
HookTranslator,
HookTranslatorOptions,
InlineTranslator,
InlineTranslatorOptions,
ReactCreateTranslatorOptions,
ReactCreateTranslatorResult,
} from './types';
2 changes: 1 addition & 1 deletion test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "..",
"extends": "../tsconfig.json",
"compilerOptions": {
"jsx": "react",
"module": "CommonJS"
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"compilerOptions": {
"outDir": "dist/esm",
"declarationDir": "dist/types",
"module": "ES2020",
"moduleResolution": "node",
"esModuleInterop": true,
"declaration": true,
"emitDeclarationOnly": true,

"strict": true,
"noImplicitReturns": true,
Expand Down
30 changes: 30 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { isAbsolute } from 'path';
import { defineConfig } from 'vite';

// https://vitejs.dev/config/

export default defineConfig({
build: {
sourcemap: true,
minify: false,

lib: {
entry: './src/index.ts',
formats: ['es', 'cjs'],
},

rollupOptions: {
input: {
index: './src/index.ts',
react: './src/react/index.ts',
},
output: {
entryFileNames: '[format]/[name].js',
chunkFileNames: '[format]/[name].js',
},
external: (source) => {
return !(isAbsolute(source) || source.startsWith('.'));
},
},
},
});

0 comments on commit 8afaf99

Please sign in to comment.