Skip to content

Commit 7ab9c72

Browse files
committed
perf: ⚡️ make postcss-load-config optional for better pkg size
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".
1 parent 5c1af16 commit 7ab9c72

File tree

4 files changed

+45
-21
lines changed

4 files changed

+45
-21
lines changed

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,19 @@
2929

3030
## Installation
3131

32-
`npm install --save-dev svelte-preprocess`
32+
`npm install -D svelte-preprocess`
3333

3434
The preprocessor module installation is up to the developer.
3535

36-
- `postcss`: `npm install --save-dev postcss`
37-
- `coffeescript`: `npm install --save-dev coffeescript`
38-
- `typescript`: `npm install --save-dev typescript`
39-
- `less`: `npm install --save-dev less`
40-
- `sass`: `npm install --save-dev node-sass`
41-
- `pug`: `npm install --save-dev pug`
42-
- `stylus`: `npm install --save-dev stylus`
36+
- `postcss`: `npm install -D postcss postcss-load-config`
37+
- `coffeescript`: `npm install -D coffeescript`
38+
- `typescript`: `npm install -D typescript`
39+
- `less`: `npm install -D less`
40+
- `sass`: `npm install -D node-sass`
41+
- `pug`: `npm install -D pug`
42+
- `stylus`: `npm install -D stylus`
43+
44+
_Note: If you want to load your `postcss` configuration from a external file, make sure to also install `postcss-load-config`._
4345

4446
## Features
4547

package-lock.json

Lines changed: 26 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "svelte-preprocess",
3-
"version": "2.16.0",
3+
"version": "3.0.0",
44
"license": "MIT",
55
"main": "src/index.js",
66
"types": "src/index.d.ts",
@@ -25,7 +25,7 @@
2525
"test:watch": "jest --no-cache --verbose --watchAll",
2626
"lint": "eslint \"src/**/*.js\"",
2727
"format": "prettier --loglevel silent --write \"src/**/*.js\" && eslint --fix \"src/**/*.js\"",
28-
"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')\"",
28+
"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')\"",
2929
"version": "npx conventional-changelog-cli -p angular -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md",
3030
"tag": "git tag -a v$npm_package_version -m 'Release v$npm_package_version'",
3131
"release": "npm run version && git add package.json && git commit -m \"chore: release v$npm_package_version\"",
@@ -58,6 +58,7 @@
5858
"node-sass": "^4.12.0",
5959
"postcss": "^7.0.14",
6060
"postcss-easy-import": "^3.0.0",
61+
"postcss-load-config": "^2.1.0",
6162
"prettier": "^1.16.4",
6263
"pug": "^2.0.3",
6364
"stylus": "^0.54.5",
@@ -70,7 +71,6 @@
7071
},
7172
"dependencies": {
7273
"detect-indent": "^6.0.0",
73-
"postcss-load-config": "^2.0.0",
7474
"strip-indent": "^2.0.0"
7575
}
7676
}

src/transformers/postcss.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const postcss = require('postcss')
2-
const postcssLoadConfig = require(`postcss-load-config`)
32

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

3837
try {
3938
/** If not, look for a postcss config file */
39+
const postcssLoadConfig = require(`postcss-load-config`)
4040
options = await postcssLoadConfig(options, options.configFilePath)
4141
} catch (e) {
4242
/** Something went wrong, do nothing */
43-
console.error(e.message)
43+
if (e.code === 'MODULE_NOT_FOUND') {
44+
console.error(
45+
`[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 ʕ•ᴥ•ʔ`,
46+
)
47+
}
4448
return { code: content, map }
4549
}
4650

0 commit comments

Comments
 (0)