rollup-plugin-lib-style 2.3.2 → 2.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +2 -2
- package/README.md +43 -0
- package/lib/index.es.js +6 -4
- package/lib/index.js +6 -4
- package/package.json +1 -1
- package/types/index.d.ts +9 -2
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2025 Daniel Amenou
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -87,6 +87,26 @@ Type: object[]<br />
|
|
|
87
87
|
Default: []<br />
|
|
88
88
|
Description: [PostCSS Plugins](https://postcss.org/docs/postcss-plugins)
|
|
89
89
|
|
|
90
|
+
### sassOptions
|
|
91
|
+
|
|
92
|
+
Type: object<br />
|
|
93
|
+
Default: {}<br />
|
|
94
|
+
Description: Options passed to the sass compiler. Can be used to set `loadPaths` for global imports/mixins.<br />
|
|
95
|
+
Example:
|
|
96
|
+
|
|
97
|
+
```js
|
|
98
|
+
// rollup.config.js
|
|
99
|
+
export default {
|
|
100
|
+
plugins: [
|
|
101
|
+
libStylePlugin({
|
|
102
|
+
sassOptions: {
|
|
103
|
+
loadPaths: ["./src/styles", "./node_modules"],
|
|
104
|
+
},
|
|
105
|
+
}),
|
|
106
|
+
],
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
90
110
|
### loaders
|
|
91
111
|
|
|
92
112
|
Type: Loader[]<br />
|
|
@@ -107,6 +127,29 @@ export default {
|
|
|
107
127
|
}
|
|
108
128
|
```
|
|
109
129
|
|
|
130
|
+
You can also override the default SCSS loader to customize sass compilation:
|
|
131
|
+
|
|
132
|
+
```js
|
|
133
|
+
// rollup.config.js
|
|
134
|
+
import sass from "sass"
|
|
135
|
+
|
|
136
|
+
const customSassLoader = {
|
|
137
|
+
name: "sass",
|
|
138
|
+
regex: /\.(sass|scss)$/,
|
|
139
|
+
process: ({filePath}) => ({
|
|
140
|
+
code: sass
|
|
141
|
+
.compile(filePath, {
|
|
142
|
+
loadPaths: ["./src/styles", "./node_modules"],
|
|
143
|
+
})
|
|
144
|
+
.css.toString(),
|
|
145
|
+
}),
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export default {
|
|
149
|
+
plugins: [libStylePlugin({loaders: [customSassLoader]})],
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
110
153
|
### exclude
|
|
111
154
|
|
|
112
155
|
Type: Array<string | RegExp> | string | RegExp<br />
|
package/lib/index.es.js
CHANGED
|
@@ -119,7 +119,9 @@ const defaultLoaders = [
|
|
|
119
119
|
{
|
|
120
120
|
name: "sass",
|
|
121
121
|
regex: /\.(sass|scss)$/,
|
|
122
|
-
process: ({filePath}) => ({
|
|
122
|
+
process: ({filePath, options}) => ({
|
|
123
|
+
code: sass.compile(filePath, options?.sassOptions || {}).css.toString(),
|
|
124
|
+
}),
|
|
123
125
|
},
|
|
124
126
|
{
|
|
125
127
|
name: "css",
|
|
@@ -131,7 +133,7 @@ const defaultLoaders = [
|
|
|
131
133
|
const replaceMagicPath = (fileContent, customPath = ".") => fileContent.replace(MAGIC_PATH_REGEX, customPath);
|
|
132
134
|
|
|
133
135
|
const libStylePlugin = (options = {}) => {
|
|
134
|
-
const {customPath, customCSSPath, customCSSInjectedPath, loaders, include, exclude, importCSS = true, ...postCssOptions} = options;
|
|
136
|
+
const {customPath, customCSSPath, customCSSInjectedPath, loaders, include, exclude, importCSS = true, sassOptions = {}, ...postCssOptions} = options;
|
|
135
137
|
const allLoaders = [...(loaders || []), ...defaultLoaders];
|
|
136
138
|
const filter = createFilter(include, exclude);
|
|
137
139
|
const getLoader = (filepath) => allLoaders.find((loader) => loader.regex.test(filepath));
|
|
@@ -150,7 +152,7 @@ const libStylePlugin = (options = {}) => {
|
|
|
150
152
|
|
|
151
153
|
modulesIds.add(id);
|
|
152
154
|
|
|
153
|
-
const rawCss = await loader.process({filePath: id, code});
|
|
155
|
+
const rawCss = await loader.process({filePath: id, code, options: {sassOptions}});
|
|
154
156
|
|
|
155
157
|
const postCssResult = await postCssLoader({code: rawCss.code, fiePath: id, options: postCssOptions});
|
|
156
158
|
|
|
@@ -207,7 +209,7 @@ const libStylePlugin = (options = {}) => {
|
|
|
207
209
|
|
|
208
210
|
const onwarn = (warning, warn) => {
|
|
209
211
|
if (warning.code === "UNRESOLVED_IMPORT" && warning.message.includes(MAGIC_PATH)) return
|
|
210
|
-
warn(warning);
|
|
212
|
+
if (typeof warn === "function") warn(warning);
|
|
211
213
|
};
|
|
212
214
|
|
|
213
215
|
export { libStylePlugin, onwarn };
|
package/lib/index.js
CHANGED
|
@@ -121,7 +121,9 @@ const defaultLoaders = [
|
|
|
121
121
|
{
|
|
122
122
|
name: "sass",
|
|
123
123
|
regex: /\.(sass|scss)$/,
|
|
124
|
-
process: ({filePath}) => ({
|
|
124
|
+
process: ({filePath, options}) => ({
|
|
125
|
+
code: sass.compile(filePath, options?.sassOptions || {}).css.toString(),
|
|
126
|
+
}),
|
|
125
127
|
},
|
|
126
128
|
{
|
|
127
129
|
name: "css",
|
|
@@ -133,7 +135,7 @@ const defaultLoaders = [
|
|
|
133
135
|
const replaceMagicPath = (fileContent, customPath = ".") => fileContent.replace(MAGIC_PATH_REGEX, customPath);
|
|
134
136
|
|
|
135
137
|
const libStylePlugin = (options = {}) => {
|
|
136
|
-
const {customPath, customCSSPath, customCSSInjectedPath, loaders, include, exclude, importCSS = true, ...postCssOptions} = options;
|
|
138
|
+
const {customPath, customCSSPath, customCSSInjectedPath, loaders, include, exclude, importCSS = true, sassOptions = {}, ...postCssOptions} = options;
|
|
137
139
|
const allLoaders = [...(loaders || []), ...defaultLoaders];
|
|
138
140
|
const filter = rollupPluginutils.createFilter(include, exclude);
|
|
139
141
|
const getLoader = (filepath) => allLoaders.find((loader) => loader.regex.test(filepath));
|
|
@@ -152,7 +154,7 @@ const libStylePlugin = (options = {}) => {
|
|
|
152
154
|
|
|
153
155
|
modulesIds.add(id);
|
|
154
156
|
|
|
155
|
-
const rawCss = await loader.process({filePath: id, code});
|
|
157
|
+
const rawCss = await loader.process({filePath: id, code, options: {sassOptions}});
|
|
156
158
|
|
|
157
159
|
const postCssResult = await postCssLoader({code: rawCss.code, fiePath: id, options: postCssOptions});
|
|
158
160
|
|
|
@@ -209,7 +211,7 @@ const libStylePlugin = (options = {}) => {
|
|
|
209
211
|
|
|
210
212
|
const onwarn = (warning, warn) => {
|
|
211
213
|
if (warning.code === "UNRESOLVED_IMPORT" && warning.message.includes(MAGIC_PATH)) return
|
|
212
|
-
warn(warning);
|
|
214
|
+
if (typeof warn === "function") warn(warning);
|
|
213
215
|
};
|
|
214
216
|
|
|
215
217
|
exports.libStylePlugin = libStylePlugin;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rollup-plugin-lib-style",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.2",
|
|
4
4
|
"description": "A Rollup plugin that converts CSS and extensions for CSS into CSS modules and imports the generated CSS files",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib/index.es.js",
|
package/types/index.d.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {PluginImpl, RollupWarning} from "rollup"
|
|
2
2
|
|
|
3
3
|
declare interface ProcessArgs {
|
|
4
4
|
code: string
|
|
5
5
|
filePath: string
|
|
6
|
+
options?: any
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare interface SassOptions {
|
|
10
|
+
loadPaths?: string[]
|
|
11
|
+
[key: string]: any
|
|
6
12
|
}
|
|
7
13
|
|
|
8
14
|
declare interface Loader {
|
|
@@ -22,10 +28,11 @@ declare interface Options {
|
|
|
22
28
|
customPath?: string
|
|
23
29
|
customCSSPath?: (id: string) => string
|
|
24
30
|
customCSSInjectedPath?: (id: string) => string
|
|
31
|
+
sassOptions?: SassOptions
|
|
25
32
|
}
|
|
26
33
|
|
|
27
34
|
declare const onwarn: (warning: RollupWarning, defaultHandler: (warning: string | RollupWarning) => void) => void
|
|
28
35
|
|
|
29
36
|
declare const libStylePlugin: PluginImpl<Options>
|
|
30
37
|
|
|
31
|
-
export {
|
|
38
|
+
export {onwarn, libStylePlugin}
|