rollup-plugin-lib-style 2.2.0 → 2.3.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/README.md CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  This plugin allows you to import CSS or SASS/SCSS files in your Rollup library and include them in the generated output. The plugin will extract the CSS or SASS/SCSS from the imported files and import them as a CSS file
4
4
 
5
-
6
5
  When creating a library, you may want to use CSS modules to create scoped styles for your components. However, when publishing your library as a standalone package, you also need to include the CSS styles that are used by your components. Rollup Plugin Lib Style automates this process by generating a CSS file that includes all the imported CSS modules.
7
6
 
8
7
  ## Why
@@ -63,6 +62,7 @@ This gives us the ability to consume only the used style
63
62
  ## Options
64
63
 
65
64
  ### importCSS
65
+
66
66
  Type: `boolean`<br />
67
67
  Default: true<br />
68
68
  Description: auto import the generated CSS
@@ -108,22 +108,31 @@ export default {
108
108
  ```
109
109
 
110
110
  ### exclude
111
+
111
112
  Type: Array<string | RegExp> | string | RegExp<br />
112
113
  Default: null<br />
113
114
  Description: exclude files from load by the loader
114
115
 
115
116
  ### customPath
117
+
116
118
  Type: string<br />
117
119
  Default: "."<br />
118
120
  Description: Change custom path for starting of reference to CSS file, useful for nested component structure
119
121
 
120
122
  ### customCSSPath
123
+
121
124
  Type: (id: string) => string<br />
122
125
  Default: undefined<br />
123
126
  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
127
 
128
+ ### customCSSInjectedPath
129
+
130
+ Type: (id: string) => string<br />
131
+ Default: undefined<br />
132
+ Description: A callback that allows you to transform the injected `import` statement path. For example, if you have deep nested css files like `./components/headers/Header.css` placed along with their corresponding js, this can be transformed to `./Header.css`. This will affect both CSS filename and the `import` statement.
125
133
 
126
134
  ## Global Styles
135
+
127
136
  In some cases, we will want to create global class names (without hash)
128
137
  we can do so by adding ".global" to the style file name.
129
138
  In this case, the scopedName will be "[local]"
@@ -146,7 +155,9 @@ export {style as default}
146
155
  ```
147
156
 
148
157
  ## Known Issues
158
+
149
159
  "Unresolved dependencies" warnings
160
+
150
161
  ```
151
162
  (!) Unresolved dependencies
152
163
  https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency
@@ -154,6 +165,7 @@ https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency
154
165
  ```
155
166
 
156
167
  These warnings can be suppressed by using the "onwarn" function
168
+
157
169
  ```js
158
170
  // rollup.config.js
159
171
  import {libStylePlugin, onwarn} from "rollup-plugin-lib-style"
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, customCSSPath, loaders, include, exclude, importCSS = true, ...postCssOptions} = options;
115
+ const {customPath, customCSSPath, customCSSInjectedPath, 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));
@@ -142,6 +142,7 @@ const libStylePlugin = (options = {}) => {
142
142
  };
143
143
 
144
144
  const cssFilePath = customCSSPath ? customCSSPath(id) : getFilePath();
145
+ const cssFileInjectedPath = customCSSInjectedPath ? customCSSInjectedPath(cssFilePath) : cssFilePath;
145
146
 
146
147
  // create a new css file with the generated hash class names
147
148
  this.emitFile({
@@ -150,7 +151,7 @@ const libStylePlugin = (options = {}) => {
150
151
  source: postCssResult.extracted.code,
151
152
  });
152
153
 
153
- const importStr = importCSS ? `import "${MAGIC_PATH}${cssFilePath.replace(loader.regex, ".css")}";\n` : "";
154
+ const importStr = importCSS ? `import "${MAGIC_PATH}${cssFileInjectedPath.replace(loader.regex, ".css")}";\n` : "";
154
155
 
155
156
  // create a new js file with css module
156
157
  return {
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, customCSSPath, loaders, include, exclude, importCSS = true, ...postCssOptions} = options;
117
+ const {customPath, customCSSPath, customCSSInjectedPath, 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));
@@ -144,6 +144,7 @@ const libStylePlugin = (options = {}) => {
144
144
  };
145
145
 
146
146
  const cssFilePath = customCSSPath ? customCSSPath(id) : getFilePath();
147
+ const cssFileInjectedPath = customCSSInjectedPath ? customCSSInjectedPath(cssFilePath) : cssFilePath;
147
148
 
148
149
  // create a new css file with the generated hash class names
149
150
  this.emitFile({
@@ -152,7 +153,7 @@ const libStylePlugin = (options = {}) => {
152
153
  source: postCssResult.extracted.code,
153
154
  });
154
155
 
155
- const importStr = importCSS ? `import "${MAGIC_PATH}${cssFilePath.replace(loader.regex, ".css")}";\n` : "";
156
+ const importStr = importCSS ? `import "${MAGIC_PATH}${cssFileInjectedPath.replace(loader.regex, ".css")}";\n` : "";
156
157
 
157
158
  // create a new js file with css module
158
159
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rollup-plugin-lib-style",
3
- "version": "2.2.0",
3
+ "version": "2.3.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",
@@ -61,7 +61,7 @@
61
61
  },
62
62
  "dependencies": {
63
63
  "fs-extra": "^11.1.0",
64
- "postcss": "8.4.17",
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
@@ -21,6 +21,7 @@ declare interface Options {
21
21
  scopedName?: string
22
22
  customPath?: string
23
23
  customCSSPath?: (id: string) => string
24
+ customCSSInjectedPath?: (id: string) => string
24
25
  }
25
26
 
26
27
  declare const onwarn: (warning: RollupWarning, defaultHandler: (warning: string | RollupWarning) => void) => void