-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(vite): support iframe blocking (#88)
Resolves #79 Co-authored-by: Jonas Thelemann <[email protected]>
- Loading branch information
1 parent
af05c06
commit 8ab8b7a
Showing
8 changed files
with
113 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// TODO: move to own library (https://github.com/leanupjs/vite-plugin-replace/pull/2) | ||
|
||
const execSrcReplacements = (src: any, replacements: any[]) => { | ||
for (const replacement of replacements) { | ||
if ( | ||
(typeof replacement.from === 'string' || | ||
replacement.from instanceof RegExp) === false | ||
) { | ||
throw new TypeError( | ||
"[vite-plugin-replace]: The replacement option 'from' is not of type 'string' or 'RegExp'.", | ||
) | ||
} else if ( | ||
(typeof replacement.to === 'string' || | ||
replacement.to instanceof Function) === false | ||
) { | ||
throw new TypeError( | ||
"[vite-plugin-replace]: The replacement option 'to' is not of type 'string' or 'Function'", | ||
) | ||
} else src = src.replace(replacement.from, replacement.to) | ||
} | ||
|
||
return src | ||
} | ||
|
||
export const replaceCodePlugin = (config: any) => { | ||
if (config === undefined) { | ||
config = { | ||
replacements: [], | ||
} | ||
} else if ((typeof config === 'object' || config !== null) === false) { | ||
throw new TypeError( | ||
"[vite-plugin-replace]: The configuration is not of type 'Object'.", | ||
) | ||
} else if (Array.isArray(config.replacements) === false) { | ||
throw new TypeError( | ||
"[vite-plugin-replace]: The configuration option 'replacement' is not of type 'Array'.", | ||
) | ||
} | ||
|
||
return { | ||
name: 'transform-file', | ||
enforce: 'pre', | ||
transform: function (src: any) { | ||
return { | ||
code: execSrcReplacements(src, config.replacements), | ||
map: null, | ||
} | ||
}, | ||
} as any | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters