Skip to content

Commit

Permalink
perf: ⚡️ make postcss-load-config optional for better pkg size
Browse files Browse the repository at this point in the history
This slims the package 207kbs

BREAKING CHANGE: To load PostCSS config automatically from a file, now it's needed to
manually install "postcss-load-config".
  • Loading branch information
kaisermann committed Aug 28, 2019
1 parent 5c1af16 commit 7ab9c72
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 21 deletions.
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,19 @@

## Installation

`npm install --save-dev svelte-preprocess`
`npm install -D svelte-preprocess`

The preprocessor module installation is up to the developer.

- `postcss`: `npm install --save-dev postcss`
- `coffeescript`: `npm install --save-dev coffeescript`
- `typescript`: `npm install --save-dev typescript`
- `less`: `npm install --save-dev less`
- `sass`: `npm install --save-dev node-sass`
- `pug`: `npm install --save-dev pug`
- `stylus`: `npm install --save-dev stylus`
- `postcss`: `npm install -D postcss postcss-load-config`
- `coffeescript`: `npm install -D coffeescript`
- `typescript`: `npm install -D typescript`
- `less`: `npm install -D less`
- `sass`: `npm install -D node-sass`
- `pug`: `npm install -D pug`
- `stylus`: `npm install -D stylus`

_Note: If you want to load your `postcss` configuration from a external file, make sure to also install `postcss-load-config`._

## Features

Expand Down
34 changes: 26 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "svelte-preprocess",
"version": "2.16.0",
"version": "3.0.0",
"license": "MIT",
"main": "src/index.js",
"types": "src/index.d.ts",
Expand All @@ -25,7 +25,7 @@
"test:watch": "jest --no-cache --verbose --watchAll",
"lint": "eslint \"src/**/*.js\"",
"format": "prettier --loglevel silent --write \"src/**/*.js\" && eslint --fix \"src/**/*.js\"",
"postinstall": "node -e \"console.log('\\u001b[36m\\u001b[1m[svelte-preprocess] Don\\'t forget to install the preprocessors packages that will be used: \\u001b[22m\\u001b[39m\\u001b[34mnode-sass/sass, stylus, less, postcss, coffeescript, pug, etc...\\u001b[0m')\"",
"postinstall": "node -e \"console.log('\\u001b[36m\\u001b[1m[svelte-preprocess] Don\\'t forget to install the preprocessors packages that will be used: \\u001b[22m\\u001b[39m\\u001b[34mnode-sass/sass, stylus, less, postcss & postcss-load-config, coffeescript, pug, etc...\\u001b[0m')\"",
"version": "npx conventional-changelog-cli -p angular -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md",
"tag": "git tag -a v$npm_package_version -m 'Release v$npm_package_version'",
"release": "npm run version && git add package.json && git commit -m \"chore: release v$npm_package_version\"",
Expand Down Expand Up @@ -58,6 +58,7 @@
"node-sass": "^4.12.0",
"postcss": "^7.0.14",
"postcss-easy-import": "^3.0.0",
"postcss-load-config": "^2.1.0",
"prettier": "^1.16.4",
"pug": "^2.0.3",
"stylus": "^0.54.5",
Expand All @@ -70,7 +71,6 @@
},
"dependencies": {
"detect-indent": "^6.0.0",
"postcss-load-config": "^2.0.0",
"strip-indent": "^2.0.0"
}
}
8 changes: 6 additions & 2 deletions src/transformers/postcss.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const postcss = require('postcss')
const postcssLoadConfig = require(`postcss-load-config`)

const process = async (
{ plugins, parser, syntax },
Expand Down Expand Up @@ -37,10 +36,15 @@ module.exports = async ({ content, filename, options, map = undefined }) => {

try {
/** If not, look for a postcss config file */
const postcssLoadConfig = require(`postcss-load-config`)
options = await postcssLoadConfig(options, options.configFilePath)
} catch (e) {
/** Something went wrong, do nothing */
console.error(e.message)
if (e.code === 'MODULE_NOT_FOUND') {
console.error(
`[svelte-preprocess] PostCSS configuration was not passed. If you expect to load it from a file, make sure to install "postcss-load-config" and try again ʕ•ᴥ•ʔ`,
)
}
return { code: content, map }
}

Expand Down

0 comments on commit 7ab9c72

Please sign in to comment.