Build: Add a commonjs bundle to dataverse

This commit is contained in:
Aria Minaei 2021-06-28 16:37:02 +02:00
parent 90d26ecd32
commit 14b3207680
9 changed files with 65 additions and 7 deletions

View file

@ -23,7 +23,11 @@ module.exports = {
parser: '@typescript-eslint/parser', parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'], plugins: ['@typescript-eslint'],
parserOptions: { parserOptions: {
project: ['./packages/**/tsconfig.json', './theatre/**/tsconfig.json'], project: [
'./packages/*/tsconfig.json',
'./packages/*/devEnv/tsconfig.json',
'./theatre/*/tsconfig.json',
],
}, },
rules: { rules: {
'@typescript-eslint/await-thenable': 'warn', '@typescript-eslint/await-thenable': 'warn',

View file

@ -1 +0,0 @@
module.exports = {}

View file

@ -0,0 +1,35 @@
import path from 'path'
import {build} from 'esbuild'
const definedGlobals = {
global: 'window',
}
function createBundles(watch: boolean) {
const pathToPackage = path.join(__dirname, '../')
const esbuildConfig: Parameters<typeof build>[0] = {
entryPoints: [path.join(pathToPackage, 'src/index.ts')],
bundle: true,
sourcemap: true,
define: definedGlobals,
watch,
platform: 'neutral',
mainFields: ['browser', 'module', 'main'],
target: ['firefox57', 'chrome58'],
conditions: ['browser', 'node'],
}
build({
...esbuildConfig,
outfile: path.join(pathToPackage, 'dist/index.cjs'),
format: 'cjs',
})
build({
...esbuildConfig,
outfile: path.join(pathToPackage, 'dist/index.mjs'),
format: 'esm',
})
}
createBundles(false)

View file

@ -0,0 +1,3 @@
{
}

View file

@ -12,20 +12,34 @@
"url": "https://github.com/AriaMinaei/theatre", "url": "https://github.com/AriaMinaei/theatre",
"directory": "packages/dataverse" "directory": "packages/dataverse"
}, },
"main": "dist/index.js", "main": "dist/index.cjs",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",
"module": "dist/index.mjs",
"exports": {
".": {
"require": "./dist/index.cjs",
"import": "./dist/index.mjs",
"default": "./dist/index.cjs",
"node": "./dist/index.cjs"
}
},
"files": [ "files": [
"dist/**/*" "dist/**/*"
], ],
"scripts": { "scripts": {
"prepack": "yarn run build", "prepack": "yarn run build",
"typecheck": "yarn run build", "typecheck": "yarn run build",
"build": "tsc --build ./tsconfig.json" "build": "run-s build:ts build:js",
"build:ts": "tsc --build ./tsconfig.json",
"build:js": "node -r esbuild-register ./devEnv/build.ts"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^26.0.23", "@types/jest": "^26.0.23",
"@types/lodash-es": "^4.17.4", "@types/lodash-es": "^4.17.4",
"@types/node": "^15.6.2", "@types/node": "^15.6.2",
"esbuild": "^0.12.5",
"esbuild-register": "^2.5.0",
"npm-run-all": "^4.1.5",
"typescript": "^4.3.2" "typescript": "^4.3.2"
}, },
"dependencies": { "dependencies": {

View file

@ -5,7 +5,7 @@
"lib": ["ESNext", "DOM"], "lib": ["ESNext", "DOM"],
"rootDir": "src", "rootDir": "src",
"types": ["jest", "node"], "types": ["jest", "node"],
"emitDeclarationOnly": false, "emitDeclarationOnly": true,
"target": "es6", "target": "es6",
"composite": true "composite": true
}, },

View file

@ -42,4 +42,4 @@
"dependencies": { "dependencies": {
"@theatre/dataverse": "workspace:*" "@theatre/dataverse": "workspace:*"
} }
} }

View file

@ -45,4 +45,4 @@
"peerDependencies": { "peerDependencies": {
"@theatre/core": "*" "@theatre/core": "*"
} }
} }

View file

@ -3760,7 +3760,10 @@ __metadata:
"@types/jest": ^26.0.23 "@types/jest": ^26.0.23
"@types/lodash-es": ^4.17.4 "@types/lodash-es": ^4.17.4
"@types/node": ^15.6.2 "@types/node": ^15.6.2
esbuild: ^0.12.5
esbuild-register: ^2.5.0
lodash-es: ^4.17.21 lodash-es: ^4.17.21
npm-run-all: ^4.1.5
typescript: ^4.3.2 typescript: ^4.3.2
languageName: unknown languageName: unknown
linkType: soft linkType: soft