Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(FaceLandmarker): default basePath aligned with tasks-vision package version #1510

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"@rollup/plugin-commonjs": "^19.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.0.0",
"@rollup/plugin-replace": "^5.0.2",
"@storybook/addon-actions": "^7.0.12",
"@storybook/addon-controls": "^7.0.12",
"@storybook/addon-essentials": "^7.0.12",
Expand Down Expand Up @@ -135,6 +136,7 @@
"typescript": "^4.7.4",
"vite": "^4.3.6",
"vite-plugin-glslify": "^2.0.1",
"vitest": "^0.32.0",
"yarn": "^1.22.17"
},
"peerDependencies": {
Expand Down
19 changes: 18 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import json from '@rollup/plugin-json'
import glslify from 'rollup-plugin-glslify'
import multiInput from 'rollup-plugin-multi-input'
import { terser } from 'rollup-plugin-terser'
import replace from '@rollup/plugin-replace'
import { version as mediapipeTasksVisionVersion } from '@mediapipe/tasks-vision/package.json'

const root = process.platform === 'win32' ? path.resolve('/') : '/'
const external = (id) => !id.startsWith('.') && !id.startsWith(root)
Expand Down Expand Up @@ -41,12 +43,18 @@ const getBabelOptions = ({ useESModules }) => ({
],
})

export const replacements = {
preventAssignment: true,
'process.env.ROLLUP_REPLACE_MEDIAPIPE_TASKS_VISION_VERSION': JSON.stringify(mediapipeTasksVisionVersion),
}

export default [
{
input: ['src/**/*.ts', 'src/**/*.tsx', '!src/index.ts'],
output: { dir: `dist`, format: 'esm' },
external,
plugins: [
replace(replacements),
multiInput(),
json(),
glslify(),
Expand All @@ -59,6 +67,7 @@ export default [
output: { dir: `dist`, format: 'esm' },
external,
plugins: [
replace(replacements),
json(),
glslify(),
babel(getBabelOptions({ useESModules: true }, '>1%, not dead, not ie 11, not op_mini all')),
Expand All @@ -71,6 +80,7 @@ export default [
output: { dir: `dist`, format: 'cjs' },
external,
plugins: [
replace(replacements),
multiInput({
transformOutputPath: (output) => output.replace(/\.[^/.]+$/, '.cjs.js'),
}),
Expand All @@ -85,6 +95,13 @@ export default [
input: `./src/index.ts`,
output: { file: `dist/index.cjs.js`, format: 'cjs' },
external,
plugins: [json(), glslify(), babel(getBabelOptions({ useESModules: false })), resolve({ extensions }), terser()],
plugins: [
replace(replacements),
json(),
glslify(),
babel(getBabelOptions({ useESModules: false })),
resolve({ extensions }),
terser(),
],
},
]
2 changes: 1 addition & 1 deletion src/core/FaceLandmarker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type FaceLandmarkerProps = {
}

export const FaceLandmarkerDefaults = {
basePath: 'https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.2-rc2/wasm',
basePath: `https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@${process.env.ROLLUP_REPLACE_MEDIAPIPE_TASKS_VISION_VERSION}/wasm`,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the purpose replacement of this PR

options: {
baseOptions: {
modelAssetPath:
Expand Down
4 changes: 3 additions & 1 deletion vite.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// vite.config.js
import glslify from 'vite-plugin-glslify'
import replace from '@rollup/plugin-replace'
import { replacements } from './rollup.config'

export default {
plugins: [glslify()],
plugins: [replace(replacements), glslify()],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rollup/plugin-replace is compatible with Vite

}