Initial commit
This commit is contained in:
commit
017f911668
|
@ -0,0 +1,8 @@
|
|||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = tab
|
||||
indent_size = 4
|
||||
end_of_line = lf
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
|
@ -0,0 +1,201 @@
|
|||
# Настройки редакторов
|
||||
|
||||
.idea
|
||||
.vscode
|
||||
|
||||
# https://github.com/github/gitignore/blob/master/Global/Linux.gitignore
|
||||
|
||||
*~
|
||||
|
||||
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||
.fuse_hidden*
|
||||
|
||||
# KDE directory preferences
|
||||
.directory
|
||||
|
||||
# Linux trash folder which might appear on any partition or disk
|
||||
.Trash-*
|
||||
|
||||
# .nfs files are created when an open file is removed but is still being accessed
|
||||
.nfs*
|
||||
|
||||
# https://github.com/github/gitignore/blob/master/Global/macOS.gitignore
|
||||
|
||||
# General
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
# https://github.com/github/gitignore/blob/master/Global/Windows.gitignore
|
||||
|
||||
# Windows thumbnail cache files
|
||||
Thumbs.db
|
||||
ehthumbs.db
|
||||
ehthumbs_vista.db
|
||||
|
||||
# Dump file
|
||||
*.stackdump
|
||||
|
||||
# Folder config file
|
||||
[Dd]esktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msix
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
# https://github.com/github/gitignore/blob/master/Global/Archives.gitignore
|
||||
|
||||
# It's better to unpack these files and commit the raw source because
|
||||
# git has its own built in compression methods.
|
||||
*.7z
|
||||
*.jar
|
||||
*.rar
|
||||
*.zip
|
||||
*.gz
|
||||
*.tgz
|
||||
*.bzip
|
||||
*.bz2
|
||||
*.xz
|
||||
*.lzma
|
||||
*.cab
|
||||
|
||||
# Packing-only formats
|
||||
*.iso
|
||||
*.tar
|
||||
|
||||
# Package management formats
|
||||
*.dmg
|
||||
*.xpi
|
||||
*.gem
|
||||
*.egg
|
||||
*.deb
|
||||
*.rpm
|
||||
*.msi
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# https://github.com/github/gitignore/blob/master/Global/Backup.gitignore
|
||||
|
||||
*.bak
|
||||
*.gho
|
||||
*.ori
|
||||
*.orig
|
||||
*.tmp
|
||||
|
||||
# https://github.com/github/gitignore/blob/master/Node.gitignore
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# TypeScript v1 declaration files
|
||||
typings/
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
.env.test
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
|
||||
# next.js build output
|
||||
.next
|
||||
|
||||
# nuxt.js build output
|
||||
.nuxt
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
# Composer
|
||||
vendor
|
|
@ -0,0 +1,29 @@
|
|||
# postcss-remove-bem-blocks
|
||||
|
||||
[PostCSS](https://github.com/postcss/postcss)-плагин для удаления БЭМ-блоков (включая их модификаторы и элементы) из конечного CSS.
|
||||
|
||||
## Установка
|
||||
|
||||
```bash
|
||||
yarn add -D @advdominion/postcss-remove-bem-blocks
|
||||
```
|
||||
|
||||
## Использование
|
||||
|
||||
`postcss.config.js`
|
||||
|
||||
```js
|
||||
const plugins = [];
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
plugins.push(
|
||||
require('@advdominion/postcss-remove-bem-blocks')({
|
||||
blocks: ['.stylepage'],
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
plugins,
|
||||
};
|
||||
```
|
|
@ -0,0 +1,33 @@
|
|||
module.exports = (options = {blocks: []}) => {
|
||||
return {
|
||||
postcssPlugin: 'postcss-remove-bem-blocks',
|
||||
Rule(rule) {
|
||||
options.blocks.forEach((block) => {
|
||||
if (rule.selector.includes(block)) {
|
||||
const regexp = new RegExp(`${block}(?![A-Za-z0-9-]+)`);
|
||||
if (rule.selectors.length === 1) {
|
||||
if (regexp.test(rule.selectors[0])) {
|
||||
rule.remove();
|
||||
}
|
||||
} else {
|
||||
const selectors = [];
|
||||
rule.selectors.forEach((selector) => {
|
||||
if (!regexp.test(selector)) {
|
||||
selectors.push(selector);
|
||||
}
|
||||
});
|
||||
if (selectors.length) {
|
||||
const cloned = rule.clone();
|
||||
cloned.selectors = selectors;
|
||||
rule.replaceWith(cloned);
|
||||
} else {
|
||||
rule.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
module.exports.postcss = true;
|
|
@ -0,0 +1,31 @@
|
|||
{
|
||||
"name": "@advdominion/postcss-remove-bem-blocks",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://bitbucket.org/advdominion/postcss-remove-bem-blocks"
|
||||
},
|
||||
"license": "MIT",
|
||||
"peerDependencies": {
|
||||
"postcss": "^8.2.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"postcss": "^8.2.8"
|
||||
},
|
||||
"prettier": {
|
||||
"printWidth": 120,
|
||||
"tabWidth": 4,
|
||||
"useTabs": true,
|
||||
"semi": true,
|
||||
"singleQuote": true,
|
||||
"quoteProps": "as-needed",
|
||||
"trailingComma": "es5",
|
||||
"bracketSpacing": false,
|
||||
"arrowParens": "always",
|
||||
"proseWrap": "preserve",
|
||||
"htmlWhitespaceSensitivity": "css",
|
||||
"vueIndentScriptAndStyle": false,
|
||||
"endOfLine": "lf"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
/* Удалить */
|
||||
.block-2 {
|
||||
}
|
||||
|
||||
/* Удалить */
|
||||
.block-2__element {
|
||||
}
|
||||
|
||||
/* Оставить */
|
||||
.block-1 {
|
||||
}
|
||||
|
||||
/* Оставить */
|
||||
.block-1__element {
|
||||
}
|
||||
|
||||
/* Оставить 1 */
|
||||
.block-1,
|
||||
.block-2 {
|
||||
}
|
||||
|
||||
/* Удалить */
|
||||
.block-2,
|
||||
.block-2__element {
|
||||
}
|
||||
|
||||
/* Удалить */
|
||||
.block-1 .block-2,
|
||||
.block-2 .block-1 {
|
||||
}
|
||||
|
||||
/* Удалить */
|
||||
.block-1.block-2 {
|
||||
}
|
||||
|
||||
/* Удалить */
|
||||
.block-1 > .block-2 {
|
||||
}
|
||||
|
||||
/* Удалить */
|
||||
.block-2 ~ .block-1 {
|
||||
}
|
||||
|
||||
/* Оставить */
|
||||
.block2 {
|
||||
}
|
||||
|
||||
/* Оставить */
|
||||
.block-22 {
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const util = require('util');
|
||||
const readFile = util.promisify(fs.readFile);
|
||||
const writeFile = util.promisify(fs.writeFile);
|
||||
const postcss = require('postcss');
|
||||
|
||||
const plugin = require('./../');
|
||||
|
||||
readFile(path.join(__dirname, 'from.css'), {
|
||||
encoding: 'utf-8',
|
||||
})
|
||||
.then((css) => {
|
||||
return postcss([
|
||||
plugin({
|
||||
blocks: ['.block-2'],
|
||||
}),
|
||||
]).process(css, {
|
||||
from: path.join(__dirname, 'from.css'),
|
||||
});
|
||||
})
|
||||
.then(({css}) => {
|
||||
writeFile(path.join(__dirname, 'to.css'), css, {
|
||||
encoding: 'utf-8',
|
||||
});
|
||||
});
|
|
@ -0,0 +1,33 @@
|
|||
/* Удалить */
|
||||
|
||||
/* Удалить */
|
||||
|
||||
/* Оставить */
|
||||
.block-1 {
|
||||
}
|
||||
|
||||
/* Оставить */
|
||||
.block-1__element {
|
||||
}
|
||||
|
||||
/* Оставить 1 */
|
||||
.block-1 {
|
||||
}
|
||||
|
||||
/* Удалить */
|
||||
|
||||
/* Удалить */
|
||||
|
||||
/* Удалить */
|
||||
|
||||
/* Удалить */
|
||||
|
||||
/* Удалить */
|
||||
|
||||
/* Оставить */
|
||||
.block2 {
|
||||
}
|
||||
|
||||
/* Оставить */
|
||||
.block-22 {
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
nanocolors@^0.2.2:
|
||||
version "0.2.12"
|
||||
resolved "https://registry.yarnpkg.com/nanocolors/-/nanocolors-0.2.12.tgz#4d05932e70116078673ea4cc6699a1c56cc77777"
|
||||
integrity sha512-SFNdALvzW+rVlzqexid6epYdt8H9Zol7xDoQarioEFcFN0JHo4CYNztAxmtfgGTVRCmFlEOqqhBpoFGKqSAMug==
|
||||
|
||||
nanoid@^3.1.25:
|
||||
version "3.1.28"
|
||||
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.1.28.tgz#3c01bac14cb6c5680569014cc65a2f26424c6bd4"
|
||||
integrity sha512-gSu9VZ2HtmoKYe/lmyPFES5nknFrHa+/DT9muUFWFMi6Jh9E1I7bkvlQ8xxf1Kos9pi9o8lBnIOkatMhKX/YUw==
|
||||
|
||||
postcss@^8.2.8:
|
||||
version "8.3.8"
|
||||
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.3.8.tgz#9ebe2a127396b4b4570ae9f7770e7fb83db2bac1"
|
||||
integrity sha512-GT5bTjjZnwDifajzczOC+r3FI3Cu+PgPvrsjhQdRqa2kTJ4968/X9CUce9xttIB0xOs5c6xf0TCWZo/y9lF6bA==
|
||||
dependencies:
|
||||
nanocolors "^0.2.2"
|
||||
nanoid "^3.1.25"
|
||||
source-map-js "^0.6.2"
|
||||
|
||||
source-map-js@^0.6.2:
|
||||
version "0.6.2"
|
||||
resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-0.6.2.tgz#0bb5de631b41cfbda6cfba8bd05a80efdfd2385e"
|
||||
integrity sha512-/3GptzWzu0+0MBQFrDKzw/DvvMTUORvgY6k6jd/VS6iCR4RDTKWH6v6WPwQoUO8667uQEf9Oe38DxAYWY5F/Ug==
|
Reference in New Issue