rollup-plugin-lib-style 2.1.0 → 2.2.1
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/README.md +5 -0
- package/lib/index.es.js +6 -2
- package/lib/index.js +6 -2
- package/package.json +2 -2
- package/types/index.d.ts +3 -2
package/README.md
CHANGED
|
@@ -117,6 +117,11 @@ Type: string<br />
|
|
|
117
117
|
Default: "."<br />
|
|
118
118
|
Description: Change custom path for starting of reference to CSS file, useful for nested component structure
|
|
119
119
|
|
|
120
|
+
### customCSSPath
|
|
121
|
+
Type: (id: string) => string<br />
|
|
122
|
+
Default: undefined<br />
|
|
123
|
+
Description: A callback that allows you to transform where to store import the generated CSS file from. For example, `Header.module.scss` transformed to `Header.module.css`, but NextJS treat `.module.scss` as CSS module, so you cannot import it directly. Then you can use `return id.replace(process.cwd(), "").replace(/\\/g, "/").replace('.module', '')` to fix it. This will affect both CSS filename and the `import` statement.
|
|
124
|
+
|
|
120
125
|
|
|
121
126
|
## Global Styles
|
|
122
127
|
In some cases, we will want to create global class names (without hash)
|
package/lib/index.es.js
CHANGED
|
@@ -112,7 +112,7 @@ const defaultLoaders = [
|
|
|
112
112
|
const replaceMagicPath = (fileContent, customPath = ".") => fileContent.replace(MAGIC_PATH_REGEX, customPath);
|
|
113
113
|
|
|
114
114
|
const libStylePlugin = (options = {}) => {
|
|
115
|
-
const {customPath, loaders, include, exclude, importCSS = true, ...postCssOptions} = options;
|
|
115
|
+
const {customPath, customCSSPath, loaders, include, exclude, importCSS = true, ...postCssOptions} = options;
|
|
116
116
|
const allLoaders = [...(loaders || []), ...defaultLoaders];
|
|
117
117
|
const filter = createFilter(include, exclude);
|
|
118
118
|
const getLoader = (filepath) => allLoaders.find((loader) => loader.regex.test(filepath));
|
|
@@ -137,7 +137,11 @@ const libStylePlugin = (options = {}) => {
|
|
|
137
137
|
|
|
138
138
|
for (const dependency of postCssResult.dependencies) this.addWatchFile(dependency);
|
|
139
139
|
|
|
140
|
-
const
|
|
140
|
+
const getFilePath = () => {
|
|
141
|
+
return id.replace(process.cwd(), "").replace(/\\/g, "/")
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const cssFilePath = customCSSPath ? customCSSPath(id) : getFilePath();
|
|
141
145
|
|
|
142
146
|
// create a new css file with the generated hash class names
|
|
143
147
|
this.emitFile({
|
package/lib/index.js
CHANGED
|
@@ -114,7 +114,7 @@ const defaultLoaders = [
|
|
|
114
114
|
const replaceMagicPath = (fileContent, customPath = ".") => fileContent.replace(MAGIC_PATH_REGEX, customPath);
|
|
115
115
|
|
|
116
116
|
const libStylePlugin = (options = {}) => {
|
|
117
|
-
const {customPath, loaders, include, exclude, importCSS = true, ...postCssOptions} = options;
|
|
117
|
+
const {customPath, customCSSPath, loaders, include, exclude, importCSS = true, ...postCssOptions} = options;
|
|
118
118
|
const allLoaders = [...(loaders || []), ...defaultLoaders];
|
|
119
119
|
const filter = rollupPluginutils.createFilter(include, exclude);
|
|
120
120
|
const getLoader = (filepath) => allLoaders.find((loader) => loader.regex.test(filepath));
|
|
@@ -139,7 +139,11 @@ const libStylePlugin = (options = {}) => {
|
|
|
139
139
|
|
|
140
140
|
for (const dependency of postCssResult.dependencies) this.addWatchFile(dependency);
|
|
141
141
|
|
|
142
|
-
const
|
|
142
|
+
const getFilePath = () => {
|
|
143
|
+
return id.replace(process.cwd(), "").replace(/\\/g, "/")
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const cssFilePath = customCSSPath ? customCSSPath(id) : getFilePath();
|
|
143
147
|
|
|
144
148
|
// create a new css file with the generated hash class names
|
|
145
149
|
this.emitFile({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rollup-plugin-lib-style",
|
|
3
|
-
"version": "2.1
|
|
3
|
+
"version": "2.2.1",
|
|
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",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
63
|
"fs-extra": "^11.1.0",
|
|
64
|
-
"postcss": "8.4.
|
|
64
|
+
"postcss": "8.4.39",
|
|
65
65
|
"postcss-modules": "4.0.0",
|
|
66
66
|
"rollup-pluginutils": "2.8.2",
|
|
67
67
|
"sass": "1.55.0"
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {PluginImpl, RollupWarning} from "rollup"
|
|
1
|
+
import { PluginImpl, RollupWarning } from "rollup"
|
|
2
2
|
|
|
3
3
|
declare interface ProcessArgs {
|
|
4
4
|
code: string
|
|
@@ -20,10 +20,11 @@ declare interface Options {
|
|
|
20
20
|
classNamePrefix?: string
|
|
21
21
|
scopedName?: string
|
|
22
22
|
customPath?: string
|
|
23
|
+
customCSSPath?: (id: string) => string
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
declare const onwarn: (warning: RollupWarning, defaultHandler: (warning: string | RollupWarning) => void) => void
|
|
26
27
|
|
|
27
28
|
declare const libStylePlugin: PluginImpl<Options>
|
|
28
29
|
|
|
29
|
-
export {onwarn, libStylePlugin}
|
|
30
|
+
export { onwarn, libStylePlugin }
|