Skip to content

Commit

Permalink
[zero][app] Modify vite config to use vite package
Browse files Browse the repository at this point in the history
  • Loading branch information
brijeshb42 committed Sep 4, 2023
1 parent 243469d commit 250590d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 115 deletions.
12 changes: 6 additions & 6 deletions apps/zero-runtime-vite-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
"react-dom": "^18.2.0"
},
"devDependencies": {
"@babel/core": "^7.22.10",
"@linaria/vite": "^4.5.4",
"@mui/utils": "^5.14.6",
"@mui/material": "^5.14.6",
"@mui/zero-tag-processor": "file:../../packages/zero-tag-processor/build",
"@types/babel__core": "^7.20.1",
"@mui/utils": "^5.14.7",
"@mui/material": "^5.14.7",
"@mui/zero-vite-plugin": "file:../../packages/zero-vite-plugin/build",
"@vitejs/plugin-react": "^4.0.4",
"vite": "4.4.9"
},
"resolutions": {
"@mui/zero-tag-processor": "file:../../packages/zero-tag-processor/build"
}
}
84 changes: 12 additions & 72 deletions apps/zero-runtime-vite-app/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { defineConfig, splitVendorChunkPlugin, type PluginOption } from 'vite';
import { defineConfig, splitVendorChunkPlugin } from 'vite';
import reactPlugin from '@vitejs/plugin-react';
import linaria from '@linaria/vite';
import { zeroVitePlugin } from '@mui/zero-vite-plugin';
import { createTheme } from '@mui/material/styles';
import { generateCss } from '@mui/zero-tag-processor/generateCss';
import { transformAsync } from '@babel/core';

const theme = createTheme();
// @TODO - Make this part of the main package
Expand All @@ -18,73 +16,15 @@ theme.applyDarkStyles = function applyDarkStyles(obj) {

const varPrefix = 'app';

function muiZeroVitePlugin(): PluginOption {
function injectMUITokensPlugin(): PluginOption {
return {
name: 'vite-mui-theme-injection-plugin',
load(id) {
if (id.endsWith('@mui/zero-runtime/styles.css')) {
return {
code: generateCss(
{
cssVariablesPrefix: varPrefix,
themeArgs: {
theme,
},
},
{},
),
map: null,
};
}
return null;
},
};
}
const extensions = ['.ts', '.tsx', '.js', '.jsx', '.mts', '.mjs', '.cts', '.cjs', '.mtsx'];

function intermediateBabelPlugin(): PluginOption {
return {
name: 'vite-intermediate-plugin',
async transform(code, id) {
const [filename] = id.split('?');
if (
!filename.includes('zero-runtime-vite-app/src') ||
!extensions.some((ext) => filename.endsWith(ext))
) {
return null;
}
const result = await transformAsync(code, {
filename,
babelrc: false,
configFile: false,
plugins: [['@mui/zero-tag-processor/pre-linaria-plugin']],
});
return {
code: result?.code ?? code,
map: result?.map,
};
},
};
}

// @TODO - Expect most of these from users of the plugin.
const linariaPlugin = linaria({
displayName: false,
sourceMap: true,
// @ts-ignore
cssVariablesPrefix: varPrefix,
themeArgs: {
theme,
},
babelOptions: {
plugins: ['@babel/plugin-syntax-jsx'],
},
});

return [injectMUITokensPlugin(), intermediateBabelPlugin(), linariaPlugin];
}

export default defineConfig({
plugins: [muiZeroVitePlugin(), reactPlugin(), splitVendorChunkPlugin()],
plugins: [
zeroVitePlugin({
cssVariablesPrefix: varPrefix,
themeArgs: {
theme,
},
}),
reactPlugin(),
splitVendorChunkPlugin(),
],
});
46 changes: 10 additions & 36 deletions apps/zero-runtime-vite-app/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@
chalk "^2.4.2"
js-tokens "^4.0.0"

"@babel/parser@^7.1.0", "@babel/parser@^7.20.7", "@babel/parser@^7.22.10", "@babel/parser@^7.22.5":
"@babel/parser@^7.22.10", "@babel/parser@^7.22.5":
version "7.22.10"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.22.10.tgz#e37634f9a12a1716136c44624ef54283cabd3f55"
integrity sha512-lNbdGsQb9ekfsnjFGhEiF4hfFqGgfOP3H3d27re3n+CGhNuTSUEQdfWk556sTLNTloczcdM5TYF2LhzmDQKyvQ==
Expand Down Expand Up @@ -966,7 +966,7 @@
debug "^4.1.0"
globals "^11.1.0"

"@babel/types@^7.0.0", "@babel/types@^7.20.7", "@babel/types@^7.22.10", "@babel/types@^7.22.5", "@babel/types@^7.4.4":
"@babel/types@^7.22.10", "@babel/types@^7.22.5", "@babel/types@^7.4.4":
version "7.22.10"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.22.10.tgz#4a9e76446048f2c66982d1a989dd12b8a2d2dc03"
integrity sha512-obaoigiLrlDZ7TUQln/8m4mSqIW2QFeOrCQc9r+xsaHGNoplVNYlRVpsfE8Vj35GEm2ZH4ZhrNYogs/3fj85kg==
Expand Down Expand Up @@ -1413,7 +1413,7 @@
dependencies:
clsx "^2.0.0"

"@mui/zero-tag-processor@file:../../packages/zero-tag-processor/build":
"@mui/zero-tag-processor@0.0.1-alpha.0", "@mui/zero-tag-processor@file:../../packages/zero-tag-processor/build":
version "0.0.1-alpha.0"
dependencies:
"@babel/core" "^7.22.10"
Expand All @@ -1426,6 +1426,13 @@
"@mui/system" "^5.14.6"
lodash.get "^4.4.2"

"@mui/zero-vite-plugin@file:../../packages/zero-vite-plugin/build":
version "0.0.1-alpha.0"
dependencies:
"@babel/core" "^7.22.10"
"@linaria/vite" "^4.5.4"
"@mui/zero-tag-processor" "0.0.1-alpha.0"

"@popperjs/core@^2.11.8":
version "2.11.8"
resolved "https://registry.yarnpkg.com/@popperjs/core/-/core-2.11.8.tgz#6b79032e760a0899cd4204710beede972a3a185f"
Expand All @@ -1439,39 +1446,6 @@
estree-walker "^2.0.1"
picomatch "^2.2.2"

"@types/babel__core@^7.20.1":
version "7.20.1"
resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.20.1.tgz#916ecea274b0c776fec721e333e55762d3a9614b"
integrity sha512-aACu/U/omhdk15O4Nfb+fHgH/z3QsfQzpnvRZhYhThms83ZnAOZz7zZAWO7mn2yyNQaA4xTO8GLK3uqFU4bYYw==
dependencies:
"@babel/parser" "^7.20.7"
"@babel/types" "^7.20.7"
"@types/babel__generator" "*"
"@types/babel__template" "*"
"@types/babel__traverse" "*"

"@types/babel__generator@*":
version "7.6.4"
resolved "https://registry.yarnpkg.com/@types/babel__generator/-/babel__generator-7.6.4.tgz#1f20ce4c5b1990b37900b63f050182d28c2439b7"
integrity sha512-tFkciB9j2K755yrTALxD44McOrk+gfpIpvC3sxHjRawj6PfnQxrse4Clq5y/Rq+G3mrBurMax/lG8Qn2t9mSsg==
dependencies:
"@babel/types" "^7.0.0"

"@types/babel__template@*":
version "7.4.1"
resolved "https://registry.yarnpkg.com/@types/babel__template/-/babel__template-7.4.1.tgz#3d1a48fd9d6c0edfd56f2ff578daed48f36c8969"
integrity sha512-azBFKemX6kMg5Io+/rdGT0dkGreboUVR0Cdm3fz9QJWpaQGJRQXl7C+6hOTCZcMll7KFyEQpgbYI2lHdsS4U7g==
dependencies:
"@babel/parser" "^7.1.0"
"@babel/types" "^7.0.0"

"@types/babel__traverse@*":
version "7.20.1"
resolved "https://registry.yarnpkg.com/@types/babel__traverse/-/babel__traverse-7.20.1.tgz#dd6f1d2411ae677dcb2db008c962598be31d6acf"
integrity sha512-MitHFXnhtgwsGZWtT68URpOvLN4EREih1u3QtQiN4VdAxWKRVvGCSvw/Qth0M0Qq3pJpnGOu5JaM/ydK7OGbqg==
dependencies:
"@babel/types" "^7.20.7"

"@types/parse-json@^4.0.0":
version "4.0.0"
resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0"
Expand Down
2 changes: 1 addition & 1 deletion packages/zero-vite-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"dependencies": {
"@babel/core": "^7.22.10",
"@linaria/vite": "^4.5.4",
"@mui/zero-tag-processor": "0.0.1-alpha.0"
"@mui/zero-tag-processor": "0.0.1-alpha.1"
},
"devDependencies": {
"@types/babel__core": "^7.20.1",
Expand Down

0 comments on commit 250590d

Please sign in to comment.