diff --git a/.stylelintrc b/.stylelintrc new file mode 100644 index 0000000..43d8e52 --- /dev/null +++ b/.stylelintrc @@ -0,0 +1,7 @@ +{ + extends: "stylelint-config-standard", + rules: { + + }, + ignoreFiles: ['node_modules/**', 'normalize.css'] +} diff --git a/README.md b/README.md index 9c6ea42..8210379 100644 --- a/README.md +++ b/README.md @@ -95,9 +95,15 @@ How to use this template to create a basic Frontend Application: - Took some finagling to get this to work during watch process - [x] Clearing/standardizing browser css - Normalize CSS http://nicolasgallagher.com/about-normalize-css/ - - [ ] PostCSS? - - [ ] (^) CSS Linting - - [ ] css variables/hierarchy? + - [..] PostCSS? + - ecosystem of parsing css files + - [..] (^) CSS Linting + - stylelint + - bem linting? https://github.com/postcss/postcss-bem-linter#stylelint-plugin + - [x] css variables/hierarchy? + - https://github.com/jonathantneal/precss + - autoprefixer for making css look cleaner (browser prefixes don't need to be added) + - list all selectors used: https://github.com/davidtheclark/list-selectors - [ ] (^) Madge? - [ ] (^) Manual in Docs - [ ] HTML template example diff --git a/docs/css-selectors.json b/docs/css-selectors.json new file mode 100644 index 0000000..9715238 --- /dev/null +++ b/docs/css-selectors.json @@ -0,0 +1 @@ +{"selectors":["body","header","#value-input"],"simpleSelectors":{"all":["body","header","#value-input"],"ids":["#value-input"],"classes":[],"attributes":[],"types":["body","header"]}} \ No newline at end of file diff --git a/package.json b/package.json index 66ffadb..1b70bf2 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "@babel/preset-env": "^7.9.5", "@babel/preset-flow": "^7.9.0", "@babel/register": "^7.9.0", + "autoprefixer": "^9.7.6", "babel-eslint": "^10.1.0", "babel-loader": "^8.1.0", "chai": "^4.2.0", @@ -74,12 +75,20 @@ "karma-mocha": "^1.3.0", "karma-sourcemap-loader": "^0.3.7", "karma-webpack": "^3.0.5", + "list-selectors": "^2.0.0", "mocha": "^6.2.3", "normalize.css": "^8.0.1", + "postcss-exclude-files": "^1.0.15", + "postcss-loader": "^3.0.0", + "postcss-preset-env": "^6.7.0", + "postcss-reporter": "^6.0.1", + "precss": "^4.0.0", "prettier": "^1.19.1", "sinon": "^7.2.7", "sinon-chai": "^3.5.0", "style-loader": "^0.23.1", + "stylelint": "^13.3.3", + "stylelint-config-standard": "^20.0.0", "webpack": "^4.43.0", "webpack-cli": "^3.3.11", "webpack-dev-server": "^3.10.3", diff --git a/postcss.config.js b/postcss.config.js new file mode 100644 index 0000000..3f51d67 --- /dev/null +++ b/postcss.config.js @@ -0,0 +1,23 @@ +/* eslint-disable no-undef */ +const listSelectors = require('list-selectors'); +const path = require('path'); +const fs = require('fs'); + +module.exports = { + plugins: [ + require('stylelint'), + require('postcss-preset-env'), + require('precss'), + require('autoprefixer'), + require('postcss-reporter'), + // TODO: this works for now, although it doesn't list the selectors after precss has processed the + // files, so it isn't quite correct + listSelectors( + ['src/**/*.css'], + {}, + (list) => { + fs.writeFileSync(path.join('docs', 'css-selectors.json'), JSON.stringify(list)); + } + ) + ] +}; diff --git a/src/base.css b/src/base.css index b284cf4..6f8285e 100644 --- a/src/base.css +++ b/src/base.css @@ -1,4 +1,8 @@ body { font-family: arial; padding: 2px; + + header { + background-color: lightblue; + } } diff --git a/webpack.config.js b/webpack.config.js index 14ebf39..a9fb084 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -118,7 +118,20 @@ module.exports = (env) => { // Load css files imported { test: /\.css$/, - use: ['style-loader', 'css-loader'] + use: [ + { + loader: 'style-loader', + }, + { + loader: 'css-loader', + options: { + importLoaders: 1, + } + }, + { + loader: 'postcss-loader' + } + ] }, // Load images imported