-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bundler): remove style injection (#4728)
* chore(deps): add concat-cli to KAIO * feat: extract CSS modules styles * feat(bundler): consolidate stylesheets * docs(bundler): update readme
- Loading branch information
1 parent
e01c24e
commit d1ae4eb
Showing
12 changed files
with
752 additions
and
615 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@kaizen/package-bundler": minor | ||
"@kaizen/components": minor | ||
--- | ||
|
||
Remove style injection |
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
14 changes: 0 additions & 14 deletions
14
packages/package-bundler/src/presets/shared-ui/bin/addBuildTools.ts
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
packages/package-bundler/src/presets/shared-ui/bin/consolidateStyles.ts
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,48 @@ | ||
import fs from "fs" | ||
import path from "path" | ||
import { getArgs } from "./getArgs.js" | ||
|
||
const args = getArgs() | ||
const { packagePath } = args | ||
|
||
const PATH_CSS_MODULES_CJS = `${packagePath}/dist/cjs/styles.css` | ||
const PATH_CSS_MODULES_ESM = `${packagePath}/dist/esm/styles.css` | ||
const PATH_TAILWIND = `${packagePath}/dist/tailwind.css` | ||
// Rollup creates an empty JS file when building Tailwind styles | ||
const PATH_TAILWIND_JS = `${packagePath}/dist/tailwind.js` | ||
const PATH_DIST_STYLES = `${packagePath}/dist/styles.css` | ||
|
||
const pathsToCombine = [PATH_TAILWIND, PATH_CSS_MODULES_ESM] | ||
const pathsToDelete = [ | ||
PATH_CSS_MODULES_CJS, | ||
PATH_CSS_MODULES_ESM, | ||
PATH_TAILWIND, | ||
PATH_TAILWIND_JS, | ||
] | ||
|
||
const combineFiles = (): void => { | ||
pathsToCombine.forEach(filePath => { | ||
const file = path.resolve(filePath) | ||
if (fs.existsSync(file) && fs.statSync(file).isFile()) { | ||
const fileContent = fs.readFileSync(file).toString() | ||
|
||
fs.appendFileSync(PATH_DIST_STYLES, `${fileContent}\n`) | ||
} | ||
}) | ||
} | ||
|
||
const deleteFiles = (): void => { | ||
pathsToDelete.forEach(filePath => { | ||
const file = path.resolve(filePath) | ||
if (fs.existsSync(file)) { | ||
fs.unlinkSync(file) | ||
} | ||
}) | ||
} | ||
|
||
const run = (): void => { | ||
combineFiles() | ||
deleteFiles() | ||
} | ||
|
||
run() |
82 changes: 0 additions & 82 deletions
82
packages/package-bundler/src/presets/shared-ui/bin/injectTailwindImports.ts
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
packages/package-bundler/src/presets/shared-ui/bin/postBuild.ts
This file was deleted.
Oops, something went wrong.
8 changes: 1 addition & 7 deletions
8
packages/package-bundler/src/presets/shared-ui/plugins-shared-ui.ts
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
35 changes: 6 additions & 29 deletions
35
packages/package-bundler/src/presets/shared-ui/rollup-tailwind.ts
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 |
---|---|---|
@@ -1,44 +1,21 @@ | ||
import path from "path" | ||
import { RollupOptions } from "rollup" | ||
import postcss from "rollup-plugin-postcss" | ||
|
||
// This file is added by bin/addBuildTools and removed in bin/postBuild | ||
const styleInjectPath = path.resolve("src/__build-tools/styleInject.js") | ||
|
||
export const rollupTailwindConfig = (): RollupOptions[] => { | ||
const sharedConfig = { | ||
const config = { | ||
input: "./src/tailwind.css", | ||
plugins: [ | ||
postcss({ | ||
modules: false, | ||
extract: false, | ||
inject: cssVariableName => | ||
`import { styleInject } from "${styleInjectPath}";\n\nstyleInject(${cssVariableName});`, | ||
inject: false, | ||
extract: "tailwind.css", | ||
extensions: [".css"], | ||
}), | ||
], | ||
} satisfies RollupOptions | ||
|
||
// CommonJS | ||
const cjsConfig = { | ||
...sharedConfig, | ||
output: { | ||
dir: "dist/cjs", | ||
format: "commonjs", | ||
entryFileNames: "tailwind.css.cjs", | ||
exports: "named", | ||
}, | ||
} satisfies RollupOptions | ||
|
||
// ESModules | ||
const esmConfig = { | ||
...sharedConfig, | ||
output: { | ||
dir: "dist/esm", | ||
format: "esm", | ||
entryFileNames: "tailwind.css.mjs", | ||
dir: "dist", | ||
}, | ||
} satisfies RollupOptions | ||
} | ||
|
||
return [cjsConfig, esmConfig] | ||
return [config] | ||
} |
Oops, something went wrong.