Skip to content

Commit

Permalink
Merge branch 'main' into lit-components-test
Browse files Browse the repository at this point in the history
  • Loading branch information
vursen committed Jan 13, 2025
2 parents 4ea748d + 08f232a commit 366f023
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
19 changes: 19 additions & 0 deletions shared/shared-vite-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { UserConfigFn, mergeConfig } from 'vite';
import { useLocalWebComponents, useLitWebComponents } from './web-components-vite-plugin';

export const mergeConfigs = (...configs: UserConfigFn[]) => {
return configs.reduce((acc, config) => mergeConfig(acc, config));
};

export const sharedConfig: UserConfigFn = (env) => ({
plugins: [
useLitWebComponents()

// Use local version of web-components, disabled by default.
// To use this, uncomment the lines below and change the path
// to your local web-components folder if needed (absolute or
// relative to this shared config).
// DO NOT COMMIT THESE CHANGES!
// useLocalWebComponents('../../web-components')
]
});
27 changes: 17 additions & 10 deletions shared/web-components-vite-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,30 @@ import { PluginOption } from 'vite';
/**
* Vite plugin that resolves Vaadin component JS modules to a
* local checkout of the web-components repository
* @param webComponentsNodeModulesPath
*
* @param webComponentsRepoPath
*/
export function useLocalWebComponents(webComponentsNodeModulesPath: string): PluginOption {
export function useLocalWebComponents(webComponentsRepoPath: string): PluginOption {
const nodeModulesPath = path.resolve(__dirname, `${webComponentsRepoPath}/node_modules`);

return {
name: 'use-local-web-components',
enforce: 'pre',
config(config) {
config.server = config.server ?? {};
config.server.fs = config.server.fs ?? {};
config.server.fs.allow = config.server.fs.allow ?? [];
config.server.fs.allow.push(webComponentsNodeModulesPath);
config.server.watch = config.server.watch ?? {};
config.server.watch.ignored = [`!${webComponentsNodeModulesPath}/**`];
config() {
return {
server: {
fs: {
allow: [nodeModulesPath]
},
watch: {
ignored: [`!${nodeModulesPath}/**`]
}
}
};
},
resolveId(id) {
if (/^(@polymer|@vaadin)/.test(id)) {
return this.resolve(path.join(webComponentsNodeModulesPath, id));
return this.resolve(path.join(nodeModulesPath, id));
}
}
};
Expand Down

0 comments on commit 366f023

Please sign in to comment.