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

Dev mode tweaks #198

Merged
merged 4 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bun.lockb
Binary file not shown.
5 changes: 4 additions & 1 deletion packages/client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"types": ["vite/client", "vitest/globals"]
"types": ["vite/client", "vitest/globals"],
"paths": {
"decorator-shared/*": ["../shared/*"]
}
},
"exclude": ["node_modules", "dist"]
}
6 changes: 6 additions & 0 deletions packages/client/vite.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import minifyLiterals from 'rollup-plugin-minify-html-literals-v3';
import path from 'path';
import { partytownRollup } from '@builder.io/partytown/utils';
import { typedCssModulesPlugin } from './typesafe-css-modules';
import { cssModulesScopedNameOption } from '../shared/css-modules-config';

export const mainBundleConfig = defineConfig({
plugins: [typedCssModulesPlugin()],
Expand Down Expand Up @@ -31,6 +32,11 @@ export const mainBundleConfig = defineConfig({
input: ['src/main.ts'],
},
},
css: {
modules: {
...cssModulesScopedNameOption,
},
},
});

export const lazyConfig = defineConfig({
Expand Down
5 changes: 4 additions & 1 deletion packages/server/css-modules-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { plugin } from 'bun';
import postcss from 'postcss';
import { cssModulesScopedNameOption } from '../shared/css-modules-config';

export async function getPostcssTokens(path: string) {
const val = await postcss([
// eslint-disable-next-line @typescript-eslint/no-var-requires
require('postcss-modules')({
getJSON: () => {},
getJSON: () => {
},
...cssModulesScopedNameOption,
}),
]).process(await Bun.file(path).text(), { from: path });

Expand Down
8 changes: 4 additions & 4 deletions packages/server/src/views/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ a.appendChild(r);

/* Merge the two manifests*/
export const getManifest = async () => {
const mainManifest = (await import(`decorator-client/dist/.vite/manifest.json`)).default;
const csrManifest = (await import(`decorator-client/dist/.vite/csr.manifest.json`)).default;
const thirdPartyManifest = (await import(`decorator-client/dist/.vite/analytics.manifest.json`)).default;
const mainManifest = (await import('decorator-client/dist/.vite/manifest.json')).default;
const csrManifest = (await import('decorator-client/dist/.vite/csr.manifest.json')).default;
const thirdPartyManifest = (await import('decorator-client/dist/.vite/analytics.manifest.json')).default;

return {
...mainManifest,
Expand Down Expand Up @@ -59,7 +59,7 @@ export const getEnvAssets = async () => {

const css: EnvAssets = {
production: manifest[entryPointPath].css.map(cdnUrl).map(cssLink).join(''),
development: '',
development: cssLink(''), // Dummy to ensure the styles-container is not empty
};

const scripts: EnvAssets = {
Expand Down
6 changes: 5 additions & 1 deletion packages/server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
"strict": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": false
"isolatedModules": false,
"paths": {
"decorator-shared/*": ["../shared/*"],
"decorator-client/*": ["../client/*"]
}
},
"exclude": ["**/*.stories.ts"]
}
7 changes: 7 additions & 0 deletions packages/shared/css-modules-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Create stable classnames in dev mode, in order to not break in HMR when loaded via other apps
export const cssModulesScopedNameOption =
process.env.NODE_ENV === 'development'
? {
generateScopedName: '[name]__[local]',
}
: {};
Loading