From df1cfa38723a6de1bb40dcde83ca6aa016acadce Mon Sep 17 00:00:00 2001 From: Maxime Quandalle Date: Fri, 28 Jan 2022 10:20:54 +0100 Subject: [PATCH] Ajout d'un build pour le script iframe --- site/package.json | 5 +-- site/source/iframe-integration-script.js | 3 +- site/tsconfig.json | 7 +++- site/vite-iframe-script.config.ts | 13 ++++++++ yarn.lock | 41 ++++++++++++------------ 5 files changed, 43 insertions(+), 26 deletions(-) create mode 100644 site/vite-iframe-script.config.ts diff --git a/site/package.json b/site/package.json index 1dafe97f3..27071ed33 100644 --- a/site/package.json +++ b/site/package.json @@ -20,9 +20,10 @@ "scripts": { "prepare": "node scripts/prepare.js", "start": "vite dev", - "build": "vite build", + "build": "vite build && yarn build:iframe-script", "build:ssr": "vite build --ssr ./source/entry-server.tsx --outDir ./dist/server --emptyOutDir && echo '{\"module\": \"commonjs\"}' > dist/package.json", "build:prerender": "node prerender.cjs", + "build:iframe-script": "vite build --config vite-iframe-script.config.ts", "preview:mon-entreprise": "sed 's|:SITE_FR||g' netlify.toml > dist/netlify.toml && cd dist && npx netlify dev", "preview:infrance": "sed 's|:SITE_EN||g' netlify.toml > dist/netlify.toml && cd dist && npx netlify dev", "typecheck:watch": "tsc --skipLibCheck --noEmit --watch", @@ -133,7 +134,7 @@ "typescript": "^4.3.2", "vite": "^2.7.13", "vite-plugin-shim-react-pdf": "^1.0.4", - "vitest": "^0.2.3", + "vitest": "^0.2.5", "xml2js": "^0.4.23" } } diff --git a/site/source/iframe-integration-script.js b/site/source/iframe-integration-script.js index 355d54581..a68c14c93 100644 --- a/site/source/iframe-integration-script.js +++ b/site/source/iframe-integration-script.js @@ -54,8 +54,7 @@ const moduleToSitePath = { } const simulateurLink = import.meta.env.VITE_FR_BASE_URL + moduleToSitePath[moduleName] ?? '' - -const url = new URL(simulateurLink, window.location.origin) +const url = new URL(simulateurLink) const params = new URLSearchParams(url.search) params.append('utm_source', 'iframe') params.append('utm_medium', 'iframe') diff --git a/site/tsconfig.json b/site/tsconfig.json index c0a2be7d9..7135c9697 100644 --- a/site/tsconfig.json +++ b/site/tsconfig.json @@ -29,5 +29,10 @@ "noEmit": true, "strict": true }, - "include": ["source", "test/**/*.ts", "vite.config.ts"] + "include": [ + "source", + "test/**/*.ts", + "vite.config.ts", + "vite-iframe-script.config.ts" + ] } diff --git a/site/vite-iframe-script.config.ts b/site/vite-iframe-script.config.ts new file mode 100644 index 000000000..643d23b32 --- /dev/null +++ b/site/vite-iframe-script.config.ts @@ -0,0 +1,13 @@ +import { defineConfig } from 'vite' + +export default defineConfig({ + build: { + lib: { + entry: './source/iframe-integration-script.js', + name: 'monEntrepriseIframe', + formats: ['iife'], + fileName: (f) => 'simulateur-iframe-integration.js', + }, + emptyOutDir: false, + }, +}) diff --git a/yarn.lock b/yarn.lock index 5d2071724..343fc6357 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2405,16 +2405,16 @@ caseless@~0.12.0: resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc" integrity sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw= -chai@^4.3.4: - version "4.3.5" - resolved "https://registry.yarnpkg.com/chai/-/chai-4.3.5.tgz#784cf398a30cd45b8980181ba1a8c866c225b5df" - integrity sha512-0gKhNDL29PUlmwz1CG42p/OaBf1v0YD3oH4//YMS1niT7rLH9tC+lqTgk+SvdbhMLd7ToTtxA61orNBmpSO/DA== +chai@^4.3.6: + version "4.3.6" + resolved "https://registry.yarnpkg.com/chai/-/chai-4.3.6.tgz#ffe4ba2d9fa9d6680cc0b370adae709ec9011e9c" + integrity sha512-bbcp3YfHCUzMOvKqsztczerVgBKSsEijCySNlHHbX3VG1nskvqjz5Rfso1gGwD6w6oOV3eI60pKuMOV5MV7p3Q== dependencies: assertion-error "^1.1.0" check-error "^1.0.2" deep-eql "^3.0.1" get-func-name "^2.0.0" - loupe "^2.3.0" + loupe "^2.3.1" pathval "^1.1.1" type-detect "^4.0.5" @@ -4718,13 +4718,12 @@ loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.2.0, loose-envify@^1.3 dependencies: js-tokens "^3.0.0 || ^4.0.0" -loupe@^2.3.0: - version "2.3.0" - resolved "https://registry.yarnpkg.com/loupe/-/loupe-2.3.0.tgz#cfae54d12853592e0ec455af490fd6867e26875e" - integrity sha512-b6TVXtF01VErh8IxN/MfdiWLQmttrenN98PPGS01kym8kGycJ9tqBXD6D+4sNEDhgE83+H0Mk1cVSl0mD1nNSg== +loupe@^2.3.1: + version "2.3.1" + resolved "https://registry.yarnpkg.com/loupe/-/loupe-2.3.1.tgz#a2e1192c9f452e4e85089766da10ac8288383947" + integrity sha512-EN1D3jyVmaX4tnajVlfbREU4axL647hLec1h/PXAb8CPDMJiYitcWF2UeLVNttRqaIqQs4x+mRvXf+d+TlDrCA== dependencies: get-func-name "^2.0.0" - type-detect "^4.0.8" lowlight@~1.11.0: version "1.11.0" @@ -6328,10 +6327,10 @@ tinypool@^0.1.1: resolved "https://registry.yarnpkg.com/tinypool/-/tinypool-0.1.1.tgz#99eaf29d030feeca2da6c1d6b33f90fc18093bc7" integrity sha512-sW2fQZ2BRb/GX5v55NkHiTrbMLx0eX0xNpP+VGhOe2f7Oo04+LeClDyM19zCE/WCy7jJ8kzIJ0Ojrxj3UhN9Sg== -tinyspy@^0.2.8: - version "0.2.8" - resolved "https://registry.yarnpkg.com/tinyspy/-/tinyspy-0.2.8.tgz#b821b3d43a7d5ae47bc575a5d8627e84fdf4e809" - integrity sha512-4VXqQzzh9gC5uOLk77cLr9R3wqJq07xJlgM9IUdCNJCet139r+046ETKbU1x7mGs7B0k7eopyH5U6yflbBXNyA== +tinyspy@^0.2.10: + version "0.2.10" + resolved "https://registry.yarnpkg.com/tinyspy/-/tinyspy-0.2.10.tgz#7f684504bda345620f7a6a8462c618ef3d055517" + integrity sha512-Qij6rGWCDjWIejxCXXVi6bNgvrYBp3PbqC4cBP/0fD6WHDOHCw09Zd13CsxrDqSR5PFq01WeqDws8t5lz5sH0A== tmp@~0.2.1: version "0.2.1" @@ -6431,7 +6430,7 @@ type-check@^0.4.0, type-check@~0.4.0: dependencies: prelude-ls "^1.2.1" -type-detect@^4.0.0, type-detect@^4.0.5, type-detect@^4.0.8: +type-detect@^4.0.0, type-detect@^4.0.5: version "4.0.8" resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c" integrity sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g== @@ -6659,17 +6658,17 @@ vite@>=2.7.13, vite@^2.7.13: optionalDependencies: fsevents "~2.3.2" -vitest@^0.2.3: - version "0.2.3" - resolved "https://registry.yarnpkg.com/vitest/-/vitest-0.2.3.tgz#aee880ed31ece34dacb215870924f7696b7ae89a" - integrity sha512-hkJpXkJJ52yyBrnoyqox6eoo4mzYmlm+OwSNSFqhMidY75wEGV1/DsAR6kx6WLucI3CtlToAzfI94WZGfgRUrg== +vitest@^0.2.5: + version "0.2.5" + resolved "https://registry.yarnpkg.com/vitest/-/vitest-0.2.5.tgz#6dec59ee7153fe5667be67acf18dbd241f939033" + integrity sha512-QruEhsNxy8ycLxYG9rrGUfHZzJ8A6YvA9ULZ4w/ecvm0Zejm1nxUar/XkRWkL2xzrqA5AjmfqDSQZ8q2bFbA0Q== dependencies: "@types/chai" "^4.3.0" "@types/chai-subset" "^1.3.3" - chai "^4.3.4" + chai "^4.3.6" local-pkg "^0.4.1" tinypool "^0.1.1" - tinyspy "^0.2.8" + tinyspy "^0.2.10" vite ">=2.7.13" void-elements@3.1.0: