Skip to content

Commit

Permalink
feat: postcss-modules, autoprefixer 設定と generateShortName のエクスポ…
Browse files Browse the repository at this point in the history
…ート追加
  • Loading branch information
a01sa01to committed Feb 28, 2024
1 parent d57cb5e commit 7aebd27
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
4 changes: 4 additions & 0 deletions packages/postcss/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.1.0 - 2024-02-28

- Add exports of `postcss-modules` and `autoprefixer` configurations, and `generateShortName` function

## 1.0.0 - 2024-02-28

- Release
2 changes: 1 addition & 1 deletion packages/postcss/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@a01sa01to/postcss-config",
"description": "My personal PostCSS config",
"version": "1.0.0",
"version": "1.1.0",
"packageManager": "[email protected]",
"license": "MIT",
"author": "a01sa01to",
Expand Down
39 changes: 24 additions & 15 deletions packages/postcss/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,36 @@ import { generateShortName } from './shortname-generator'
const shortNameGenerator = generateShortName()
const shortNameMemo = new Map<string, string>()

const autoprefixerConfig: autoprefixer.Options = {
overrideBrowserslist: ['last 2 versions', 'not dead'],
}

const modulesConfig = {
generateScopedName: (
name: string,
_filename: string,
css: string,
): string => {
const hash = `${name}__${css}`
if (shortNameMemo.has(hash)) {
return shortNameMemo.get(hash)!
}
const shortName = shortNameGenerator.next().value
shortNameMemo.set(hash, shortName)
return shortName
},
scopeBehaviour: 'local' as const,
}

const config: Config = {
plugins: [
postcssCombineDuplicatedSelectors(),
postcssCalc({}),
autoprefixer({
overrideBrowserslist: ['last 2 versions', 'not dead'],
}),
postcssModules({
generateScopedName: (name, _filename, css) => {
const hash = `${name}__${css}`
if (shortNameMemo.has(hash)) {
return shortNameMemo.get(hash)!
}
const shortName = shortNameGenerator.next().value
shortNameMemo.set(hash, shortName)
return shortName
},
scopeBehaviour: 'local',
}),
autoprefixer(autoprefixerConfig),
postcssModules(modulesConfig),
cssnano(),
],
}

export default config
export { autoprefixerConfig, generateShortName, modulesConfig }

0 comments on commit 7aebd27

Please sign in to comment.