rollup-plugin-lib-style 2.0.1 → 2.1.0

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Daniel Amenou
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -112,6 +112,11 @@ Type: Array<string | RegExp> | string | RegExp<br />
112
112
  Default: null<br />
113
113
  Description: exclude files from load by the loader
114
114
 
115
+ ### customPath
116
+ Type: string<br />
117
+ Default: "."<br />
118
+ Description: Change custom path for starting of reference to CSS file, useful for nested component structure
119
+
115
120
 
116
121
  ## Global Styles
117
122
  In some cases, we will want to create global class names (without hash)
package/lib/index.es.js CHANGED
@@ -109,10 +109,10 @@ const defaultLoaders = [
109
109
  },
110
110
  ];
111
111
 
112
- const replaceMagicPath = (fileContent) => fileContent.replace(MAGIC_PATH_REGEX, ".");
112
+ const replaceMagicPath = (fileContent, customPath = ".") => fileContent.replace(MAGIC_PATH_REGEX, customPath);
113
113
 
114
114
  const libStylePlugin = (options = {}) => {
115
- const {loaders, include, exclude, importCSS = true, ...postCssOptions} = options;
115
+ const {customPath, 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));
@@ -172,7 +172,7 @@ const libStylePlugin = (options = {}) => {
172
172
  fs
173
173
  .readFile(currentPath)
174
174
  .then((buffer) => buffer.toString())
175
- .then(replaceMagicPath)
175
+ .then((fileContent) => replaceMagicPath(fileContent, customPath))
176
176
  .then((fileContent) => fs.writeFile(currentPath, fileContent))
177
177
  )
178
178
  );
package/lib/index.js CHANGED
@@ -111,10 +111,10 @@ const defaultLoaders = [
111
111
  },
112
112
  ];
113
113
 
114
- const replaceMagicPath = (fileContent) => fileContent.replace(MAGIC_PATH_REGEX, ".");
114
+ const replaceMagicPath = (fileContent, customPath = ".") => fileContent.replace(MAGIC_PATH_REGEX, customPath);
115
115
 
116
116
  const libStylePlugin = (options = {}) => {
117
- const {loaders, include, exclude, importCSS = true, ...postCssOptions} = options;
117
+ const {customPath, 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));
@@ -174,7 +174,7 @@ const libStylePlugin = (options = {}) => {
174
174
  fs
175
175
  .readFile(currentPath)
176
176
  .then((buffer) => buffer.toString())
177
- .then(replaceMagicPath)
177
+ .then((fileContent) => replaceMagicPath(fileContent, customPath))
178
178
  .then((fileContent) => fs.writeFile(currentPath, fileContent))
179
179
  )
180
180
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rollup-plugin-lib-style",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
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
@@ -19,6 +19,7 @@ declare interface Options {
19
19
  postCssPlugins?: object[]
20
20
  classNamePrefix?: string
21
21
  scopedName?: string
22
+ customPath?: string
22
23
  }
23
24
 
24
25
  declare const onwarn: (warning: RollupWarning, defaultHandler: (warning: string | RollupWarning) => void) => void