diff --git a/.github/workflows/buildDeploy.yml b/.github/workflows/buildDeploy.yml
index 8f580e0b..8e3ae6b9 100644
--- a/.github/workflows/buildDeploy.yml
+++ b/.github/workflows/buildDeploy.yml
@@ -4,7 +4,8 @@ on: push
env:
CI: true
- NODE_VER: 19
+ NODE_VER: 20
+ NETLIFY_SITE_ID: 89194942-bd48-4c23-a181-7e489c17eabc
jobs:
lint:
@@ -75,6 +76,25 @@ jobs:
- name: test built libs
run: npm run test:dist
+ - name: Deploy visual tests to Netlify
+ uses: nwtgck/actions-netlify@v2
+ id: deploy-to-netlify
+ with:
+ publish-dir: dist/dev
+ github-token: ${{ secrets.GITHUB_TOKEN }}
+ deploy-message: '[${{ github.ref_name }}@${{ env.GIT_SHORT_REVISION }}] ${{ env.GIT_SHORT_COMMIT_MESSAGE }}'
+ enable-pull-request-comment: false
+ enable-commit-comment: false
+ enable-commit-status: false
+ # Use custom alias for non master branch Deploy Previews only
+ alias: ${{ github.ref_name != 'master' && env.RUN_NAME || '' }}
+ github-deployment-environment: '[${{ env.GIT_BRANCH }}] visual tests'
+ fails-without-credentials: true
+ production-deploy: ${{ github.ref_name == 'master' }}
+ env:
+ NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
+ NETLIFY_SITE_ID: ${{ env.NETLIFY_SITE_ID }}
+
deploy:
runs-on: ubuntu-latest
needs: [lint, test]
diff --git a/build.js b/build.js
index 5cab8280..2ba8c292 100644
--- a/build.js
+++ b/build.js
@@ -1,7 +1,10 @@
-import {context, build} from 'esbuild'
import {rm} from 'node:fs/promises'
+import url from 'node:url'
+import {context, build} from 'esbuild'
+import open from 'open'
-await rm('./dist', {recursive: true, force: true})
+const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
+const distOutdir = './dist/dev'
const buildOpts = {
entryPoints: ['./src/index.tsx', './src/Img.tsx', './src/useImage.tsx'],
@@ -16,16 +19,44 @@ const buildOpts = {
jsx: 'automatic',
}
-// build esm version
-await build(buildOpts)
+const devBuildOpts = {
+ entryPoints: ['./dev/app.tsx', './dev/index.html', './dev/sw.js'],
+ bundle: true,
+ splitting: true,
+ outdir: distOutdir,
+ format: 'esm',
+ sourcemap: true,
+ minify: process.env.NODE_ENV !== 'development',
+ jsxDev: true,
+ jsx: 'automatic',
+ loader: {'.html': 'copy'},
+}
+
+await rm('./dist', {recursive: true, force: true})
-// build cjs version
-await build({
- ...buildOpts,
- format: 'cjs',
- outdir: './dist/cjs',
- splitting: false,
-})
+if (process.env.NODE_ENV !== 'development') {
+ // build esm version
+ await Promise.all([
+ build(buildOpts),
+
+ // build cjs version
+ build({
+ ...buildOpts,
+ format: 'cjs',
+ outdir: './dist/cjs',
+ splitting: false,
+ }),
+
+ // build dev site
+ build(devBuildOpts),
+ ])
+} else {
+ const ctx = await context(devBuildOpts)
+ await ctx.watch()
+ let {port} = await ctx.serve({servedir: distOutdir})
+ open(`http://localhost:${port}`)
+ await ctx.dispose()
+}
process.on('unhandledRejection', console.error)
process.on('uncaughtException', console.error)
diff --git a/dev/Preloader.tsx b/dev/Preloader.tsx
deleted file mode 100644
index 1dcdbf5a..00000000
--- a/dev/Preloader.tsx
+++ /dev/null
@@ -1,16 +0,0 @@
-import React, {Component} from 'react'
-
-export default () => (
-
-
-
-)
diff --git a/dev/cat.jpg b/dev/cat.jpg
deleted file mode 100644
index d2bd0bb2..00000000
Binary files a/dev/cat.jpg and /dev/null differ
diff --git a/dev/index.js b/dev/index.js
index 75f744d9..e20ff052 100644
--- a/dev/index.js
+++ b/dev/index.js
@@ -1,11 +1,19 @@
import url from 'node:url'
+import {parseArgs} from 'node:util'
import {context} from 'esbuild'
import {rm} from 'node:fs/promises'
import open from 'open'
// const app = express()
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
-const outdir = __dirname + '../dist'
+const outdir = __dirname + '../dist/dev'
+const {
+ values: {build},
+} = parseArgs({
+ options: {
+ build: {type: 'boolean', default: false},
+ },
+})
await rm(outdir, {recursive: true, force: true})
@@ -27,10 +35,14 @@ const buildOpts = {
}
const ctx = await context(buildOpts)
-await ctx.watch()
-let {port} = await ctx.serve({servedir: outdir})
-open(`http://localhost:${port}`)
-
+if (!build) {
+ await ctx.watch()
+ let {port} = await ctx.serve({servedir: outdir})
+ open(`http://localhost:${port}`)
+} else {
+ await ctx.rebuild()
+ await ctx.dispose()
+}
process.on('unhandledRejection', console.error)
process.on('uncaughtException', console.error)
process.on('exit', () => ctx && ctx.dispose())
diff --git a/dev/loader.gif b/dev/loader.gif
deleted file mode 100644
index 8909745a..00000000
Binary files a/dev/loader.gif and /dev/null differ
diff --git a/package.json b/package.json
index abef585a..21e29684 100644
--- a/package.json
+++ b/package.json
@@ -3,10 +3,10 @@
"version": "4.1.0",
"description": "React Image is an tag replacement for react, featuring preloader and multiple image fallback support",
"scripts": {
- "build": "npm run build:types && node build.js",
- "build:types": "tsc -p tsconfig.json --emitDeclarationOnly",
+ "build": "node build.js && npm run build:types && mv dist/src/*.d.ts dist",
+ "build:types": "tsc -p tsconfig.json",
"codecov": "codecov",
- "dev": "node --watch dev/index.js",
+ "dev": "NODE_ENV=development node --watch build.js",
"pretty": "prettier \"**/*.{?(cj|mj|t|j)s?(on|on5|x),y?(a)ml,graphql,md,css}\" --write",
"isNewerThanPublished": "semver `npm -s view $npm_package_name dist-tags.${TAG:-latest}` --range \"<$npm_package_version\" > /dev/null && echo true || echo false",
"test": "jest",
@@ -46,7 +46,7 @@
],
"module": "dist/esm/index.js",
"main": "dist/cjs/index.js",
- "types": "react-image.d.ts",
+ "types": "dist/index.d.ts",
"type": "module",
"author": "mbrevda@gmail.com",
"license": "MIT",
diff --git a/src/index.tsx b/src/index.tsx
index da94882a..c6c569f2 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -1,3 +1,3 @@
import Img, {ImgProps} from './Img'
import useImage, {useImageProps} from './useImage'
-export {Img, useImage, ImgProps, useImageProps}
+export {Img, useImage, type ImgProps, type useImageProps}
diff --git a/tsconfig.json b/tsconfig.json
index a9d3c4a1..bd327088 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,8 +1,9 @@
{
"compilerOptions": {
"declaration": true, // emit declerations
- "declarationDir": ".", // to this dir
- "outDir": "./jsSrc", // but all other code to this dir
+ "emitDeclarationOnly": true, // emit declerations for all files
+ "declarationDir": "./dist", // to this dir
+ "outDir": "./dist", // but all other code to this dir
"sourceMap": true, // allow sourcemap support
"strictNullChecks": true, // enable strict null checks as a best practice
// "module": "es6", // specify module code generation