@@ -10,89 +10,91 @@ import asyncTranspiler from './transpilers/async';
1010
1111import Preset from '../' ;
1212
13- const preactPreset = new Preset (
14- 'preact-cli' ,
15- [ 'js' , 'jsx' , 'ts' , 'tsx' , 'json' , 'less' , 'scss' , 'sass' , 'styl' , 'css' ] ,
16- {
17- preact$ : 'preact' ,
18- // preact-compat aliases for supporting React dependencies:
19- react : 'preact-compat' ,
20- 'react-dom' : 'preact-compat' ,
21- 'create-react-class' : 'preact-compat/lib/create-react-class' ,
22- 'react-addons-css-transition-group' : 'preact-css-transition-group' ,
23- }
24- ) ;
13+ export default function initialize ( ) {
14+ const preactPreset = new Preset (
15+ 'preact-cli' ,
16+ [ 'js' , 'jsx' , 'ts' , 'tsx' , 'json' , 'less' , 'scss' , 'sass' , 'styl' , 'css' ] ,
17+ {
18+ preact$ : 'preact' ,
19+ // preact-compat aliases for supporting React dependencies:
20+ react : 'preact-compat' ,
21+ 'react-dom' : 'preact-compat' ,
22+ 'create-react-class' : 'preact-compat/lib/create-react-class' ,
23+ 'react-addons-css-transition-group' : 'preact-css-transition-group' ,
24+ }
25+ ) ;
2526
26- preactPreset . registerTranspiler ( module => / \. j s x ? $ / . test ( module . path ) , [
27- {
28- transpiler : babelTranspiler ,
29- options : {
30- presets : [
31- // babel preset env starts with latest, then drops rules.
32- // We don't have env, so we just support latest
33- 'latest' ,
34- 'stage-1' ,
35- ] ,
36- plugins : [
37- 'transform-object-assign' ,
38- 'transform-decorators-legacy' ,
39- [ 'transform-react-jsx' , { pragma : 'h' } ] ,
40- [
41- 'jsx-pragmatic' ,
42- {
43- module : 'preact' ,
44- export : 'h' ,
45- import : 'h' ,
46- } ,
27+ preactPreset . registerTranspiler ( module => / \. j s x ? $ / . test ( module . path ) , [
28+ {
29+ transpiler : babelTranspiler ,
30+ options : {
31+ presets : [
32+ // babel preset env starts with latest, then drops rules.
33+ // We don't have env, so we just support latest
34+ 'latest' ,
35+ 'stage-1' ,
36+ ] ,
37+ plugins : [
38+ 'transform-object-assign' ,
39+ 'transform-decorators-legacy' ,
40+ [ 'transform-react-jsx' , { pragma : 'h' } ] ,
41+ [
42+ 'jsx-pragmatic' ,
43+ {
44+ module : 'preact' ,
45+ export : 'h' ,
46+ import : 'h' ,
47+ } ,
48+ ] ,
4749 ] ,
48- ] ,
50+ } ,
4951 } ,
50- } ,
51- ] ) ;
52+ ] ) ;
5253
53- // For these routes we need to enable css modules
54- const cssModulesPaths = [
55- '/src/components' ,
56- '/components' ,
57- '/src/routes' ,
58- '/routes' ,
59- ] ;
54+ // For these routes we need to enable css modules
55+ const cssModulesPaths = [
56+ '/src/components' ,
57+ '/components' ,
58+ '/src/routes' ,
59+ '/routes' ,
60+ ] ;
6061
61- const cssModulesRegex = extension =>
62- new RegExp ( `^(${ cssModulesPaths . join ( '|' ) } )\\/.*\\.${ extension } $` ) ;
62+ const cssModulesRegex = extension =>
63+ new RegExp ( `^(${ cssModulesPaths . join ( '|' ) } )\\/.*\\.${ extension } $` ) ;
6364
64- const cssTypes = {
65- css : [ ] ,
66- 's[a|c]ss' : [ { transpiler : sassTranspiler } ] ,
67- less : [ { transpiler : lessTranspiler } ] ,
68- styl : [ { transpiler : stylusTranspiler } ] ,
69- } ;
65+ const cssTypes = {
66+ css : [ ] ,
67+ 's[a|c]ss' : [ { transpiler : sassTranspiler } ] ,
68+ less : [ { transpiler : lessTranspiler } ] ,
69+ styl : [ { transpiler : stylusTranspiler } ] ,
70+ } ;
7071
71- Object . keys ( cssTypes ) . forEach ( cssType => {
72- preactPreset . registerTranspiler (
73- module => cssModulesRegex ( cssType ) . test ( module . path ) ,
74- [
75- ...cssTypes [ cssType ] ,
76- { transpiler : stylesTranspiler , options : { module : true } } ,
77- ]
78- ) ;
72+ Object . keys ( cssTypes ) . forEach ( cssType => {
73+ preactPreset . registerTranspiler (
74+ module => cssModulesRegex ( cssType ) . test ( module . path ) ,
75+ [
76+ ...cssTypes [ cssType ] ,
77+ { transpiler : stylesTranspiler , options : { module : true } } ,
78+ ]
79+ ) ;
7980
80- preactPreset . registerTranspiler (
81- module => new RegExp ( `\\.${ cssType } $` ) . test ( module . path ) ,
82- [ ...cssTypes [ cssType ] , { transpiler : stylesTranspiler } ]
83- ) ;
84- } ) ;
81+ preactPreset . registerTranspiler (
82+ module => new RegExp ( `\\.${ cssType } $` ) . test ( module . path ) ,
83+ [ ...cssTypes [ cssType ] , { transpiler : stylesTranspiler } ]
84+ ) ;
85+ } ) ;
8586
86- preactPreset . registerTranspiler ( module => / \. j s o n / . test ( module . path ) , [
87- { transpiler : jsonTranspiler } ,
88- ] ) ;
87+ preactPreset . registerTranspiler ( module => / \. j s o n / . test ( module . path ) , [
88+ { transpiler : jsonTranspiler } ,
89+ ] ) ;
8990
90- // Support for !async statements
91- preactPreset . registerTranspiler (
92- ( ) => false /* never load without explicit statement */ ,
93- [ { transpiler : asyncTranspiler } ]
94- ) ;
91+ // Support for !async statements
92+ preactPreset . registerTranspiler (
93+ ( ) => false /* never load without explicit statement */ ,
94+ [ { transpiler : asyncTranspiler } ]
95+ ) ;
9596
96- preactPreset . registerTranspiler ( ( ) => true , [ { transpiler : rawTranspiler } ] ) ;
97+ preactPreset . registerTranspiler ( ( ) => true , [ { transpiler : rawTranspiler } ] ) ;
9798
98- export default preactPreset ;
99+ return preactPreset ;
100+ }
0 commit comments