@tarojs/rn-style-transformer 4.0.0-beta.87 → 4.0.0-beta.89

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.
Files changed (95) hide show
  1. package/.eslintrc.js +8 -0
  2. package/LICENSE +8 -8
  3. package/__tests__/config.spec.js +203 -0
  4. package/__tests__/index.spec.js +252 -0
  5. package/__tests__/platform.spec.js +78 -0
  6. package/__tests__/styles/b.css +3 -0
  7. package/__tests__/styles/b.less +3 -0
  8. package/__tests__/styles/b.rn.css +3 -0
  9. package/__tests__/styles/b.scss +3 -0
  10. package/__tests__/styles/b.styl +3 -0
  11. package/__tests__/styles/c.css +3 -0
  12. package/__tests__/styles/c.less +5 -0
  13. package/__tests__/styles/c.rn.scss +5 -0
  14. package/__tests__/styles/c.scss +5 -0
  15. package/__tests__/styles/d.rn.scss +3 -0
  16. package/__tests__/styles/d.scss +3 -0
  17. package/__tests__/styles/mixins.scss +18 -0
  18. package/__tests__/styles/nest.rn.less +3 -0
  19. package/__tests__/styles/variable.scss +1 -0
  20. package/babel.config.js +12 -0
  21. package/dist/index.js +3 -3
  22. package/dist/index.js.map +1 -1
  23. package/dist/transforms/StyleSheet/ColorPropType.js.map +1 -1
  24. package/dist/transforms/StyleSheet/ImageStylePropTypes.js +1 -1
  25. package/dist/transforms/StyleSheet/ImageStylePropTypes.js.map +1 -1
  26. package/dist/transforms/StyleSheet/ShadowPropTypesIOS.js +1 -1
  27. package/dist/transforms/StyleSheet/ShadowPropTypesIOS.js.map +1 -1
  28. package/dist/transforms/StyleSheet/StyleSheetValidation.js +1 -1
  29. package/dist/transforms/StyleSheet/StyleSheetValidation.js.map +1 -1
  30. package/dist/transforms/StyleSheet/TextStylePropTypes.js +1 -1
  31. package/dist/transforms/StyleSheet/TextStylePropTypes.js.map +1 -1
  32. package/dist/transforms/StyleSheet/TransformPropTypes.js.map +1 -1
  33. package/dist/transforms/StyleSheet/ViewStylePropTypes.js +1 -1
  34. package/dist/transforms/StyleSheet/ViewStylePropTypes.js.map +1 -1
  35. package/dist/transforms/StyleSheet/deprecatedPropType.js.map +1 -1
  36. package/dist/transforms/StyleSheet/normalizeColor.js.map +1 -1
  37. package/dist/transforms/index.js +5 -5
  38. package/dist/transforms/index.js.map +1 -1
  39. package/dist/transforms/less.js.map +1 -1
  40. package/dist/transforms/postcss.js +1 -5
  41. package/dist/transforms/postcss.js.map +1 -1
  42. package/dist/transforms/sass.js +0 -3
  43. package/dist/transforms/sass.js.map +1 -1
  44. package/dist/transforms/stylus.js +1 -1
  45. package/dist/transforms/stylus.js.map +1 -1
  46. package/dist/utils/index.js.map +1 -1
  47. package/dist/utils/reporterSkip.js.map +1 -1
  48. package/jest.config.js +8 -0
  49. package/package.json +31 -32
  50. package/src/config/rn-stylelint.json +5 -0
  51. package/src/index.ts +52 -0
  52. package/src/transforms/StyleSheet/ColorPropType.ts +76 -0
  53. package/src/transforms/StyleSheet/ImageResizeMode.ts +50 -0
  54. package/src/transforms/StyleSheet/ImageStylePropTypes.ts +62 -0
  55. package/src/transforms/StyleSheet/LayoutPropTypes.ts +559 -0
  56. package/src/transforms/StyleSheet/ShadowPropTypesIOS.ts +48 -0
  57. package/src/transforms/StyleSheet/StyleSheetValidation.ts +81 -0
  58. package/src/transforms/StyleSheet/TextStylePropTypes.ts +123 -0
  59. package/src/transforms/StyleSheet/TransformPropTypes.ts +109 -0
  60. package/src/transforms/StyleSheet/ViewStylePropTypes.ts +61 -0
  61. package/src/transforms/StyleSheet/deprecatedPropType.ts +31 -0
  62. package/src/transforms/StyleSheet/index.ts +5 -0
  63. package/src/transforms/StyleSheet/normalizeColor.ts +369 -0
  64. package/src/transforms/index.ts +229 -0
  65. package/src/transforms/less.ts +50 -0
  66. package/src/transforms/postcss.ts +95 -0
  67. package/src/transforms/sass.ts +148 -0
  68. package/src/transforms/stylus.ts +124 -0
  69. package/src/types/index.ts +242 -0
  70. package/src/utils/index.ts +229 -0
  71. package/src/utils/lessImport.ts +50 -0
  72. package/src/utils/reporterSkip.ts +27 -0
  73. package/tsconfig.json +12 -0
  74. package/dist/index.d.ts +0 -8
  75. package/dist/transforms/StyleSheet/ColorPropType.d.ts +0 -10
  76. package/dist/transforms/StyleSheet/ImageResizeMode.d.ts +0 -6
  77. package/dist/transforms/StyleSheet/ImageStylePropTypes.d.ts +0 -128
  78. package/dist/transforms/StyleSheet/LayoutPropTypes.d.ts +0 -388
  79. package/dist/transforms/StyleSheet/ShadowPropTypesIOS.d.ts +0 -45
  80. package/dist/transforms/StyleSheet/StyleSheetValidation.d.ts +0 -15
  81. package/dist/transforms/StyleSheet/TextStylePropTypes.d.ts +0 -191
  82. package/dist/transforms/StyleSheet/TransformPropTypes.d.ts +0 -67
  83. package/dist/transforms/StyleSheet/ViewStylePropTypes.d.ts +0 -136
  84. package/dist/transforms/StyleSheet/deprecatedPropType.d.ts +0 -13
  85. package/dist/transforms/StyleSheet/index.d.ts +0 -2
  86. package/dist/transforms/StyleSheet/normalizeColor.d.ts +0 -10
  87. package/dist/transforms/index.d.ts +0 -56
  88. package/dist/transforms/less.d.ts +0 -2
  89. package/dist/transforms/postcss.d.ts +0 -13
  90. package/dist/transforms/sass.d.ts +0 -2
  91. package/dist/transforms/stylus.d.ts +0 -3
  92. package/dist/types/index.d.ts +0 -206
  93. package/dist/utils/index.d.ts +0 -21
  94. package/dist/utils/lessImport.d.ts +0 -5
  95. package/dist/utils/reporterSkip.d.ts +0 -7
package/.eslintrc.js ADDED
@@ -0,0 +1,8 @@
1
+ const config = require('../../.eslintrc.js')
2
+
3
+ module.exports = {
4
+ ...config,
5
+ rules: {
6
+ ...config.rules
7
+ }
8
+ }
package/LICENSE CHANGED
@@ -154,8 +154,15 @@ See `/LICENSE` for details of the license.
154
154
 
155
155
  ==================
156
156
 
157
+ MIT (stencil-vue2-output-target):
158
+ The following files embed [stencil-vue2-output-target](https://github.com/diondree/stencil-vue2-output-target) MIT:
159
+ `/packages/taro-components-library-vue2/src/vue-component-lib/utils.ts`
160
+ See `/LICENSE` for details of the license.
161
+
162
+ ==================
163
+
157
164
  MIT (weui):
158
- The following files embed [weui](https://github.com/Tencent/weui) MIT:
165
+ The following files embed [stencil-vue2-output-target](https://github.com/Tencent/weui) MIT:
159
166
  `/packages/taro-components/src/components/*.scss`
160
167
  See `/LICENSE.txt` for details of the license.
161
168
 
@@ -165,10 +172,3 @@ Apache-2.0 (intersection-observer):
165
172
  The following files embed [intersection-observer](https://github.com/GoogleChromeLabs/intersection-observer) Apache-2.0:
166
173
  `/packages/taro-api/src/polyfill/intersection-observer.ts`
167
174
  See `/LICENSE.txt` for details of the license.
168
-
169
- ==================
170
-
171
- MIT (babel-plugin-jsx-dom-expressions):
172
- The following files embed [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/blob/main/packages/babel-plugin-jsx-dom-expressions) MIT:
173
- `/packages/babel-plugin-transform-solid-jsx/src/*`
174
- See `/LICENSE` for details of the license.
@@ -0,0 +1,203 @@
1
+ import { recursiveMerge } from '@tarojs/helper'
2
+ import * as path from 'path'
3
+
4
+ import StyleTransform, { getWrapedCSS } from '../src/transforms'
5
+
6
+ const defaultConfig = {
7
+ designWidth: 750,
8
+ deviceRatio: {
9
+ 640: 2.34 / 2,
10
+ 750: 1,
11
+ 828: 1.81 / 2
12
+ },
13
+ alias: {
14
+ '@': path.resolve(__dirname, './styles')
15
+ },
16
+ rn: {
17
+ postcss: {
18
+ options: {
19
+ plugins: []
20
+ }
21
+ },
22
+ sass: {
23
+ options: {},
24
+ additionalData: ''
25
+ },
26
+ less: {
27
+ options: {},
28
+ additionalData: ''
29
+ },
30
+ stylus: {
31
+ options: {},
32
+ additionalData: ''
33
+ }
34
+ }
35
+ }
36
+
37
+ async function run (src, filename = './__tests__/styles/a.css', debug) {
38
+ let options = { platform: 'android' }
39
+ let config
40
+
41
+ if (typeof src === 'object') {
42
+ ({
43
+ src,
44
+ filename = './__tests__/styles/a.css',
45
+ options = { platform: 'android' },
46
+ debug,
47
+ config
48
+ } = src || {})
49
+ }
50
+
51
+ const mergeConfig = recursiveMerge({}, defaultConfig, config)
52
+ // console.log('mergeConfig', JSON.stringify(mergeConfig, null, ' '))
53
+ const styleTransform = new StyleTransform(mergeConfig)
54
+ const css = await styleTransform.transform(src, filename, options)
55
+ if (debug) {
56
+ // eslint-disable-next-line
57
+ console.log(filename + ' source: ', src)
58
+ // eslint-disable-next-line
59
+ console.log(filename + ' target: ', css)
60
+ }
61
+ return css
62
+ }
63
+
64
+ describe('style transform with config options', () => {
65
+ it('config.sass option', async () => {
66
+ const css = await run({
67
+ src: `
68
+ .test {
69
+ color: $base-color;
70
+ height: 10px;
71
+ }
72
+ `,
73
+ config: {
74
+ sass: {
75
+ resource: [
76
+ '__tests__/styles/variable.scss',
77
+ '__tests__/styles/b.css'
78
+ ],
79
+ projectDirectory: path.resolve(__dirname, '..'),
80
+ data: '.data { width: 200px }'
81
+ }
82
+ },
83
+ filename: './__tests__/styles/a.scss'
84
+ })
85
+ expect(css).toEqual(getWrapedCSS(`{
86
+ "brn": {
87
+ "color": "red"
88
+ },
89
+ "data": {
90
+ "width": scalePx2dp(100)
91
+ },
92
+ "test": {
93
+ "color": "#c6538c",
94
+ "height": scalePx2dp(5)
95
+ }
96
+ }`))
97
+ })
98
+
99
+ it('config.sass option without projectDirectory', async () => {
100
+ const css = await run({
101
+ src: `
102
+ .test {
103
+ color: $base-color;
104
+ height: 10px;
105
+ }
106
+ `,
107
+ filename: './__tests__/styles/a.scss',
108
+ config: {
109
+ sass: {
110
+ resource: [
111
+ path.resolve(__dirname, 'styles/variable.scss'),
112
+ path.resolve(__dirname, 'styles/b.css')
113
+ ],
114
+ projectDirectory: path.resolve(__dirname, '..'),
115
+ data: '.data { width: 200px }'
116
+ }
117
+ }
118
+ })
119
+ expect(css).toEqual(getWrapedCSS(`{
120
+ "brn": {
121
+ "color": "red"
122
+ },
123
+ "data": {
124
+ "width": scalePx2dp(100)
125
+ },
126
+ "test": {
127
+ "color": "#c6538c",
128
+ "height": scalePx2dp(5)
129
+ }
130
+ }`))
131
+ })
132
+
133
+ it('config.postcss disable pxTransform', async () => {
134
+ const css = await run(`
135
+ .test {
136
+ height: 10px;
137
+ }
138
+ `)
139
+ expect(css).toEqual(getWrapedCSS(`{
140
+ "test": {
141
+ "height": scalePx2dp(5)
142
+ }
143
+ }`))
144
+ })
145
+
146
+ it('config.postcss disable scalePx2dp', async () => {
147
+ const config = {
148
+ rn: {
149
+ postcss: {
150
+ options: {
151
+ plugins: []
152
+ },
153
+ scalable: false
154
+ }
155
+ }
156
+ }
157
+ const css = await run({
158
+ src: `
159
+ .test {
160
+ height: 10px;
161
+ }
162
+ `,
163
+ config
164
+ })
165
+ expect(css).toEqual(getWrapedCSS(`{
166
+ "test": {
167
+ "height": 5
168
+ }
169
+ }`))
170
+ })
171
+ it('config.alias in css', async () => {
172
+ const css = await run("@import '@/b.css';")
173
+ expect(css).toEqual(getWrapedCSS(`{
174
+ "brn": {
175
+ "color": "red"
176
+ }
177
+ }`))
178
+ })
179
+
180
+ it('config.alias in sass', async () => {
181
+ const css = await run({
182
+ src: "@import '@/b.scss';",
183
+ filename: './__tests__/styles/a.scss'
184
+ })
185
+ expect(css).toEqual(getWrapedCSS(`{
186
+ "b": {
187
+ "color": "red"
188
+ }
189
+ }`))
190
+ })
191
+
192
+ it('config.alias in less', async () => {
193
+ const css = await run({
194
+ src: "@import '@/b.less';",
195
+ filename: './__tests__/styles/a.less'
196
+ })
197
+ expect(css).toEqual(getWrapedCSS(`{
198
+ "b": {
199
+ "color": "red"
200
+ }
201
+ }`))
202
+ })
203
+ })
@@ -0,0 +1,252 @@
1
+ import StyleTransform, { getWrapedCSS } from '../src/transforms'
2
+
3
+ // 初始化
4
+ const styleTransform = new StyleTransform({})
5
+
6
+ async function run (src, filename = './__tests__/styles/a.css', debug) {
7
+ let options = { platform: 'android' }
8
+
9
+ if (typeof src === 'object') {
10
+ ({
11
+ src,
12
+ filename = './__tests__/styles/a.css',
13
+ options = { platform: 'android' },
14
+ debug
15
+ } = src || {})
16
+ }
17
+
18
+ const css = await styleTransform.transform(src, filename, options)
19
+ if (debug) {
20
+ // eslint-disable-next-line
21
+ console.log(filename + ' source: ', src)
22
+ // eslint-disable-next-line
23
+ console.log(filename + ' target: ', css)
24
+ }
25
+ return css
26
+ }
27
+
28
+ describe('style transform', () => {
29
+ it('.css transform basic', async () => {
30
+ const css = await run(`
31
+ .test {
32
+ color: red;
33
+ height: 10px;
34
+ }
35
+ `)
36
+ expect(css).toEqual(getWrapedCSS(`{
37
+ "test": {
38
+ "color": "red",
39
+ "height": scalePx2dp(5)
40
+ }
41
+ }`))
42
+ })
43
+
44
+ it('.css transform viewport unit', async () => {
45
+ const css = await run(`
46
+ .test {
47
+ height: 10vh;
48
+ }
49
+ `)
50
+ expect(css).toEqual(getWrapedCSS(`{
51
+ "test": {
52
+ "height": scaleVu2dp(10, 'vh')
53
+ },
54
+ "__viewportUnits": true
55
+ }`))
56
+ })
57
+
58
+ it('.css transform @import', async () => {
59
+ const css = await run(`
60
+ @import './b.css';
61
+ .test {
62
+ color: red;
63
+ }
64
+ `)
65
+ expect(css).toEqual(getWrapedCSS(`{
66
+ "brn": {
67
+ "color": "red"
68
+ },
69
+ "test": {
70
+ "color": "red"
71
+ }
72
+ }`))
73
+ })
74
+
75
+ it('.css import source omit extension', async () => {
76
+ const css = await run("@import './b';", './__tests__/styles/a.css')
77
+ expect(css).toEqual(getWrapedCSS(`{
78
+ "brn": {
79
+ "color": "red"
80
+ }
81
+ }`))
82
+ })
83
+
84
+ it('.sass transform basic', async () => {
85
+ const css = await run(`
86
+ .test {
87
+ color: red;
88
+ }
89
+ `, './__tests__/styles/a.scss')
90
+ expect(css).toEqual(getWrapedCSS(`{
91
+ "test": {
92
+ "color": "red"
93
+ }
94
+ }`))
95
+ })
96
+ //
97
+ it('.sass transform @import', async () => {
98
+ const css = await run(`
99
+ @import './b.scss';
100
+ .test {
101
+ color: red;
102
+ }
103
+ `, './__tests__/styles/a.scss')
104
+ expect(css).toEqual(getWrapedCSS(`{
105
+ "b": {
106
+ "color": "red"
107
+ },
108
+ "test": {
109
+ "color": "red"
110
+ }
111
+ }`))
112
+ })
113
+ it('.sass transform @import css file', async () => {
114
+ const css = await run(`
115
+ @import './c.css';
116
+ .test {
117
+ color: red;
118
+ }
119
+ `, './__tests__/styles/a.scss')
120
+ expect(css).toEqual(getWrapedCSS(`{
121
+ "c": {
122
+ "color": "red"
123
+ },
124
+ "test": {
125
+ "color": "red"
126
+ }
127
+ }`))
128
+ })
129
+
130
+ it('.sass transform @import with mixins', async () => {
131
+ const css = await run(`
132
+ @import './mixins.scss';
133
+ .test {
134
+ color: red;
135
+ @include hairline(width);
136
+ }
137
+ `, './__tests__/styles/a.scss')
138
+ expect(css).toEqual(getWrapedCSS(`{
139
+ "test": {
140
+ "color": "red",
141
+ "width": scalePx2dp(0.5)
142
+ }
143
+ }`))
144
+ })
145
+
146
+ it('.sass import source omit extension', async () => {
147
+ const css = await run("@import './b';", './__tests__/styles/a.scss')
148
+ expect(css).toEqual(getWrapedCSS(`{
149
+ "b": {
150
+ "color": "red"
151
+ }
152
+ }`))
153
+ })
154
+
155
+ it('.less transform basic', async () => {
156
+ const css = await run(`
157
+ .test {
158
+ color: red;
159
+ }
160
+ `, './__tests__/styles/a.less')
161
+ expect(css).toEqual(getWrapedCSS(`{
162
+ "test": {
163
+ "color": "red"
164
+ }
165
+ }`))
166
+ })
167
+
168
+ it('.less transform @import', async () => {
169
+ const css = await run(`
170
+ @import './b.less';
171
+ .test {
172
+ color: red;
173
+ }
174
+ `, './__tests__/styles/a.less')
175
+ expect(css).toEqual(getWrapedCSS(`{
176
+ "b": {
177
+ "color": "red"
178
+ },
179
+ "test": {
180
+ "color": "red"
181
+ }
182
+ }`))
183
+ })
184
+
185
+ it('.less tranform nest import', async () => {
186
+ const css = await run(`
187
+ @import './c.less';
188
+ .test {
189
+ color: red;
190
+ }
191
+ `, './__tests__/styles/a.less')
192
+ expect(css).toEqual(getWrapedCSS(`{
193
+ "nest": {
194
+ "color": "red"
195
+ },
196
+ "c": {
197
+ "color": "red"
198
+ },
199
+ "test": {
200
+ "color": "red"
201
+ }
202
+ }`))
203
+ })
204
+
205
+ it('.less tranform node_modules file import', async () => {
206
+ const css = await run("@import 'less/test/browser/css/global-vars/simple.css';", './__tests__/styles/a.less')
207
+ expect(css).toEqual(getWrapedCSS(`{
208
+ "test": {
209
+ "color": "red"
210
+ }
211
+ }`))
212
+ })
213
+
214
+ it('.less import source omit extension', async () => {
215
+ const css = await run("@import './b';", './__tests__/styles/a.less')
216
+ expect(css).toEqual(getWrapedCSS(`{
217
+ "b": {
218
+ "color": "red"
219
+ }
220
+ }`))
221
+ })
222
+
223
+ it('.styl transform basic', async () => {
224
+ const css = await run(`
225
+ .test {
226
+ color: red;
227
+ }
228
+ `, './__tests__/styles/a.styl')
229
+ expect(css).toEqual(getWrapedCSS(`{
230
+ "test": {
231
+ "color": "#f00"
232
+ }
233
+ }`))
234
+ })
235
+
236
+ it('.styl transform @import', async () => {
237
+ const css = await run(`
238
+ @import './b.styl';
239
+ .test {
240
+ color: red;
241
+ }
242
+ `, './__tests__/styles/a.styl')
243
+ expect(css).toEqual(getWrapedCSS(`{
244
+ "b": {
245
+ "color": "#f00"
246
+ },
247
+ "test": {
248
+ "color": "#f00"
249
+ }
250
+ }`))
251
+ })
252
+ })
@@ -0,0 +1,78 @@
1
+ import StyleTransform, { getWrapedCSS } from '../src/transforms'
2
+
3
+ // 初始化config
4
+ const styleTransform = new StyleTransform({})
5
+
6
+ async function run (src, filename = './__tests__/styles/a.css', options = { platform: 'android' }, debug) {
7
+ if (typeof src === 'object') {
8
+ ({
9
+ src,
10
+ filename = './__tests__/styles/a.css',
11
+ options = { platform: 'android' },
12
+ debug
13
+ } = src || {})
14
+ }
15
+
16
+ const css = await styleTransform.transform(src, filename, options)
17
+ if (debug) {
18
+ // eslint-disable-next-line
19
+ console.log(filename + ' source: ', src)
20
+ // eslint-disable-next-line
21
+ console.log(filename + ' target: ', css)
22
+ }
23
+ return css
24
+ }
25
+
26
+ describe('style transform in cross platform', () => {
27
+ it('postcss cross platform conditional compile', async () => {
28
+ const css = await run(`
29
+ .test {
30
+ color: red;
31
+ }
32
+ /* #ifdef rn */
33
+ .rn { width: 100px }
34
+ /* #endif */
35
+ /* #ifndef rn */
36
+ .h5 { errSet: 100px }
37
+ /* #endif */
38
+ `)
39
+ expect(css).toEqual(getWrapedCSS(`{
40
+ "test": {
41
+ "color": "red"
42
+ },
43
+ "rn": {
44
+ "width": scalePx2dp(50)
45
+ }
46
+ }`))
47
+ })
48
+
49
+ it('not surport style', async () => {
50
+ const css = await run(`
51
+ .test {
52
+ o: 0.5;
53
+ background: red;
54
+ }
55
+ `)
56
+ expect(css).toEqual(getWrapedCSS(`{
57
+ "test": {
58
+ "o": 0.5,
59
+ "backgroundColor": "red"
60
+ }
61
+ }`))
62
+ })
63
+
64
+ it('nest sass import cross platform', async () => {
65
+ const css = await run({
66
+ filename: './__tests__/styles/a.scss',
67
+ src: "@import './c.scss';"
68
+ })
69
+ expect(css).toEqual(getWrapedCSS(`{
70
+ "drn": {
71
+ "color": "red"
72
+ },
73
+ "crn": {
74
+ "color": "red"
75
+ }
76
+ }`))
77
+ })
78
+ })
@@ -0,0 +1,3 @@
1
+ .b {
2
+ color: red;
3
+ }
@@ -0,0 +1,3 @@
1
+ .b {
2
+ color: red;
3
+ }
@@ -0,0 +1,3 @@
1
+ .brn {
2
+ color: red;
3
+ }
@@ -0,0 +1,3 @@
1
+ .b {
2
+ color: red;
3
+ }
@@ -0,0 +1,3 @@
1
+ .b {
2
+ color: red;
3
+ }
@@ -0,0 +1,3 @@
1
+ .c {
2
+ color: red;
3
+ }
@@ -0,0 +1,5 @@
1
+ @import ' ./nest.less ';
2
+
3
+ .c {
4
+ color: red;
5
+ }
@@ -0,0 +1,5 @@
1
+ @import './d.scss';
2
+
3
+ .crn {
4
+ color: red;
5
+ }
@@ -0,0 +1,5 @@
1
+ @import './d.scss';
2
+
3
+ .c {
4
+ color: red;
5
+ }
@@ -0,0 +1,3 @@
1
+ .drn {
2
+ color: red;
3
+ }
@@ -0,0 +1,3 @@
1
+ .d {
2
+ color: red;
3
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * 对于不能打包到 RN 的样式,可以用 mixins 引入,相对美观一些
3
+ */
4
+ @mixin eject($attr, $value) {
5
+ /*postcss-pxtransform rn eject enable*/
6
+ #{$attr}: $value;
7
+ /*postcss-pxtransform rn eject disable*/
8
+ }
9
+
10
+ /**
11
+ * // TODO 1px 的线在各端上实现方式不同,统一出来后续再兼容,目前注意两点:
12
+ * 1. Taro 中大写的 PX 不会被编译成 rpx/em,但 RN 还未兼容该写法
13
+ * 2. H5 中 1px(转成 rem 后实际小于 0.5px) + border-radius 会导致 border 不显示
14
+ */
15
+ @mixin hairline($attr) {
16
+ #{$attr}: 1px;
17
+ @include eject($attr, 1PX);
18
+ }
@@ -0,0 +1,3 @@
1
+ .nest {
2
+ color: red;
3
+ }
@@ -0,0 +1 @@
1
+ $base-color: #c6538c;
@@ -0,0 +1,12 @@
1
+ module.exports = {
2
+ presets: [
3
+ [
4
+ '@babel/preset-env',
5
+ {
6
+ targets: {
7
+ node: 'current'
8
+ }
9
+ }
10
+ ]
11
+ ]
12
+ }
package/dist/index.js CHANGED
@@ -49,7 +49,7 @@ async function transform(src, filename, options) {
49
49
  }
50
50
  const ext = path.extname(filename);
51
51
  if (RN_CSS_EXT.includes(ext)) {
52
- const styleTransform = getSingleStyleTransform(options.config || {});
52
+ const styleTransform = getSingleStyleTransform(options.config);
53
53
  const styles = await styleTransform.transform(src, filename, options);
54
54
  return upstreamTransformer.transform({
55
55
  src: styles,
@@ -62,11 +62,11 @@ async function transform(src, filename, options) {
62
62
  exports.transform = transform;
63
63
  function rollupTransform(options) {
64
64
  return {
65
- name: 'rn-style-transformer', // this name will show up in warnings and errors
65
+ name: 'rn-style-transformer',
66
66
  async transform(src, filename) {
67
67
  const ext = path.extname(filename);
68
68
  if (RN_CSS_EXT.includes(ext)) {
69
- const styleTransform = getSingleStyleTransform(options.config || {});
69
+ const styleTransform = getSingleStyleTransform(options.config);
70
70
  const code = await styleTransform.transform(src, filename, options);
71
71
  return { code };
72
72
  }