rollup-plugin-lib-style 1.1.0 → 1.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 CHANGED
@@ -1,16 +1,17 @@
1
1
  # rollup-plugin-lib-style
2
2
 
3
- A Rollup plugin that converts CSS and extensions for CSS into CSS modules and imports the generated CSS files.
4
- Under the assumption the library will be bundled by webpack or another bundler, it gives us the ability to consume only the used styles
3
+ A Rollup plugin that converts CSS and CSS extension languages into CSS modules and imports the generated CSS files.
4
+ This plugin gives you the ability to build a library that imports its styles (under the assumption the library will be bundled with a bundler like webpack or rollup).
5
+
5
6
 
6
7
  ## Why
7
8
 
8
- Today there are 2 main ways to bundle and import style from a library
9
+ Today there are 2 main ways to bundle and import styles from a library
9
10
 
10
- - bundle all the styles into one big CSS file
11
- - use CSS-in-JS
11
+ - Having a single CSS file for all styles in the library
12
+ - Using CSS-in-JS (styled-components, emotion, ...)
12
13
 
13
- These two ways have some disadvantages, when we are using one big file we are importing style that probably will not be necessary, and when you are using CSS-in-JS you will increase the HTML size
14
+ These two ways have some disadvantages, when we are having a single CSS file, we are importing styles that probably will not be necessary, and when we are using CSS-in-JS we are increasing the HTML size
14
15
 
15
16
  This plugin brings you the ability to consume only the used styles from the library
16
17
 
@@ -25,10 +26,10 @@ npm i rollup-plugin-lib-style --save-dev
25
26
 
26
27
  ```js
27
28
  // rollup.config.js
28
- import {libStyleLoader} from "rollup-plugin-lib-style"
29
+ import {libStylePlugin} from "rollup-plugin-lib-style"
29
30
 
30
31
  export default {
31
- plugins: [libStyleLoader()],
32
+ plugins: [libStylePlugin()],
32
33
  }
33
34
  ```
34
35
 
@@ -99,7 +100,7 @@ const lessLoader = {
99
100
  }
100
101
 
101
102
  export default {
102
- plugins: [libStyleLoader({loaders: [lessLoader]})],
103
+ plugins: [libStylePlugin({loaders: [lessLoader]})],
103
104
  }
104
105
  ```
105
106
 
@@ -109,6 +110,28 @@ Default: null<br />
109
110
  Description: exclude files from load by the loader
110
111
 
111
112
 
113
+ ## Global Styles
114
+ In some cases, we will want to create global class names (without hash)
115
+ we can do so by adding ".global" to the style file name.
116
+ In this case, the scopedName will be "[local]"
117
+ Example: myStyle.global.css, mySecondStyle.global.scss
118
+
119
+ ```css
120
+ // myStyle.global.css
121
+ .myStyle {
122
+ background-color: red;
123
+ }
124
+ ```
125
+
126
+ ```js
127
+ // myStyle.global.css.js
128
+ import "./myComponent/style.css"
129
+
130
+ var style = {myStyle: "myStyle"}
131
+
132
+ export {style as default}
133
+ ```
134
+
112
135
  ## Known Issues
113
136
  "Unresolved dependencies" warnings
114
137
  ```
@@ -124,7 +147,7 @@ import {libStylePlugin, onwarn} from "rollup-plugin-lib-style"
124
147
 
125
148
  export default {
126
149
  onwarn,
127
- plugins: [libStyleLoader()],
150
+ plugins: [libStylePlugin()],
128
151
  }
129
152
  ```
130
153
 
package/lib/index.es.js CHANGED
@@ -32,9 +32,11 @@ const postCssLoader = async ({code, fiePath, options}) => {
32
32
 
33
33
  const modulesExported = {};
34
34
 
35
+ const isGlobalStyle = /\.global.(css|scss|sass|less|stylus)$/.test(fiePath);
36
+
35
37
  postCssPlugins.unshift(
36
38
  postcssModules({
37
- generateScopedName: classNamePrefix + scopedName,
39
+ generateScopedName: isGlobalStyle ? "[local]" : classNamePrefix + scopedName,
38
40
  getJSON: (cssFileName, json) => (modulesExported[cssFileName] = json),
39
41
  })
40
42
  );
package/lib/index.js CHANGED
@@ -45,9 +45,11 @@ const postCssLoader = async ({code, fiePath, options}) => {
45
45
 
46
46
  const modulesExported = {};
47
47
 
48
+ const isGlobalStyle = /\.global.(css|scss|sass|less|stylus)$/.test(fiePath);
49
+
48
50
  postCssPlugins.unshift(
49
51
  postcssModules__default["default"]({
50
- generateScopedName: classNamePrefix + scopedName,
52
+ generateScopedName: isGlobalStyle ? "[local]" : classNamePrefix + scopedName,
51
53
  getJSON: (cssFileName, json) => (modulesExported[cssFileName] = json),
52
54
  })
53
55
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rollup-plugin-lib-style",
3
- "version": "1.1.0",
3
+ "version": "1.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",