-
Notifications
You must be signed in to change notification settings - Fork 23
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
feat: inject tailwind and global styles #4641
Closed
HeartSquared
wants to merge
8
commits into
heartsquared/dist-inject-styles
from
heartsquared/inject-tailwind
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3927a48
feat: inject tailwind and global styles
HeartSquared 530cb1d
fixup! feat: inject tailwind and global styles
HeartSquared 7bc05cb
chore: prefix tailwind classes
HeartSquared b677b05
ci: import global styles into component files
HeartSquared 11f8092
ci: use scoped path for global styles
HeartSquared ac6f878
ci: fix CJS global styles import
HeartSquared 389b0f7
test tailwind-only injection
61c73f1
ci: add dist/tailwind.css to side effects
HeartSquared File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,61 @@ | ||
import fs from "fs" | ||
import path from "path" | ||
|
||
const DIST_STYLES_PATH = path.resolve(__dirname, "../dist/tailwind.css") | ||
|
||
const addGlobalStylesImport = async (dirOrFile: string): Promise<void> => { | ||
if (fs.statSync(dirOrFile).isDirectory()) { | ||
const dirContent = await fs.promises.readdir(dirOrFile) | ||
|
||
dirContent.forEach(content => { | ||
const contentPath = path.join(dirOrFile, content) | ||
addGlobalStylesImport(contentPath) | ||
}) | ||
return | ||
} | ||
|
||
const filePath = path.resolve(dirOrFile) | ||
if (fs.statSync(filePath).isFile()) { | ||
const sourceFile = dirOrFile | ||
.replace(/dist\/(esm|cjs)/, "src") | ||
.replace(/(c|m)js$/, "tsx") | ||
if (!fs.existsSync(sourceFile)) { | ||
return | ||
} | ||
|
||
const stylesPath = path.relative(path.dirname(filePath), DIST_STYLES_PATH) | ||
const fileContent = fs.readFileSync(filePath).toString() | ||
|
||
const isESM = dirOrFile.includes("dist/esm") | ||
if (isESM) { | ||
fs.writeFile( | ||
filePath, | ||
`import "${stylesPath}"\n${fileContent}`, | ||
err => err | ||
) | ||
return | ||
} | ||
|
||
const isCJS = dirOrFile.includes("dist/cjs") | ||
if (isCJS) { | ||
const fileSplit = fileContent.split("\n") | ||
fileSplit.splice(1, 0, `require("${stylesPath}")`) | ||
const newContent = fileSplit.join("\n") | ||
fs.writeFile(filePath, newContent, err => err) | ||
return | ||
} | ||
} | ||
} | ||
|
||
const DIST_DIRS = ["dist/cjs", "dist/esm"] | ||
|
||
DIST_DIRS.forEach(dir => { | ||
;(async () => { | ||
try { | ||
addGlobalStylesImport(dir) | ||
} catch (e) { | ||
// eslint-disable-next-line no-console | ||
console.error("Directory not found", e) | ||
} | ||
})() | ||
}) |
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 was deleted.
Oops, something went wrong.
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 +1,6 @@ | ||
@import "./foundation/styles.css"; | ||
@layer tokens, normalize, reset; | ||
|
||
@import "@kaizen/design-tokens/css/variables.css" layer(tokens); | ||
@import "./foundation/_normalize.css" layer(normalize); | ||
@import "./foundation/_fonts.css" layer(reset); | ||
@import "./foundation/_reset.css" layer(reset); |
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,3 @@ | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; |
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,17 @@ | ||
// ts-check | ||
/** @type {import('tailwindcss').Config} */ | ||
|
||
const { Preset } = require("@kaizen/tailwind") | ||
|
||
module.exports = { | ||
content: { | ||
relative: true, | ||
files: ["./src/**/*.tsx"], | ||
}, | ||
presets: [Preset], | ||
corePlugins: { | ||
preflight: false, | ||
}, | ||
plugins: [], | ||
prefix: "kz-", | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: Use scoped path
@kaizen/components
to stop agadoo failing