-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
6,247 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import React from 'react'; | ||
import {expect} from 'chai'; | ||
import {renderToStaticNodeStream} from 'react-dom/server'; | ||
|
||
import {getUsedStyles, createStyleStream} from "../src/streamers/cssStream"; | ||
|
||
describe('css stream', () => { | ||
it('simple map', () => { | ||
const map = getUsedStyles( | ||
`<div class="a"><div class="b c d"><div class=f></div></div>`, | ||
{ | ||
a: [1], | ||
b: [2], | ||
d: [3], | ||
e: [4], | ||
f: [5, 6], | ||
} | ||
); | ||
expect(map).to.deep.equal({ | ||
1: true, | ||
2: true, | ||
3: true, | ||
5: true, | ||
6: true, | ||
}) | ||
}); | ||
|
||
it('React.renderToStream', async () => { | ||
const styles = {}; | ||
const cssStream = createStyleStream({ | ||
a: ['file1'], | ||
b: ['file1', 'file2'], | ||
zz: ['file3'], | ||
notused: ['file4'] | ||
}, style => { | ||
styles[style] = (styles[style] || 0) + 1; | ||
}); | ||
const output = renderToStaticNodeStream( | ||
<div> | ||
<div className="a"> | ||
<div className="a b c"> | ||
<div className="xx"> | ||
</div> | ||
</div> | ||
<div className="zz"> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
|
||
const streamString = async (readStream) => { | ||
const result = []; | ||
for await (const chunk of readStream) { | ||
console.log('XX', chunk); | ||
result.push(chunk); | ||
} | ||
return result.join('') | ||
}; | ||
|
||
const [tr, base] = await Promise.all([ | ||
streamString(output.pipe(cssStream)), | ||
streamString(output) | ||
]); | ||
|
||
expect(base).to.be.equal(tr); | ||
expect(styles).to.deep.equal({ | ||
file1: 1, | ||
file2: 1, | ||
file3: 1, | ||
}) | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/usr/bin/env node | ||
|
||
require('../dist/scanForImports'); | ||
require('../dist/cjs/scanners/scanForImports'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env node | ||
|
||
require('../dist/cjs/scanners/scanForStyles'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"env": { | ||
"server": { | ||
"plugins": ["react-imported-component/babel", "babel-plugin-dynamic-import-node"] | ||
}, | ||
"client": { | ||
"plugins": ["react-hot-loader/babel","react-imported-component/babel"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
*.log | ||
.cache | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright 漏 Benoit Tremblay | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
import {hot} from 'react-hot-loader'; | ||
import React from 'react'; | ||
import importedComponent from 'react-imported-component'; | ||
|
||
import { Helmet } from 'react-helmet'; | ||
import { Switch, Route, Redirect } from 'react-router-dom'; | ||
|
||
import HelloWorld from './HelloWorld'; | ||
|
||
const HelloWorld2 = importedComponent(() => import('./HelloWorld2')); | ||
|
||
export default hot(module)(function App() { | ||
return ( | ||
<div> | ||
<Helmet defaultTitle="Hello World!"> | ||
<meta charSet="utf-8" /> | ||
</Helmet> | ||
App | ||
<Switch> | ||
<Route exact path="/" component={HelloWorld} /> | ||
<Route exact path="/codeSplit" component={HelloWorld2} /> | ||
<Redirect to="/" /> | ||
</Switch> | ||
</div> | ||
); | ||
}) |
16 changes: 16 additions & 0 deletions
16
examples/SSR/parcel-react-styled-components/app/HelloWorld.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Dead simple component for the hello world (hi mom!) | ||
|
||
import React from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
import './HelloWorld.scss'; | ||
|
||
export default function HelloWorld() { | ||
return <div> | ||
<h1 className="hello-world">Hello world</h1> | ||
<p style={{ textAlign: 'center' }}> | ||
This is an ordinary react component. | ||
<br /> | ||
<Link to="/codeSplit">Click here</Link> to see a code-split component. | ||
</p> | ||
</div>; | ||
} |
13 changes: 13 additions & 0 deletions
13
examples/SSR/parcel-react-styled-components/app/HelloWorld.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// With Parcel, you have nothing to setup for SCSS, you just write! | ||
|
||
$primary-color: #0098da; | ||
|
||
body { | ||
margin: 0; | ||
} | ||
|
||
.hello-world { | ||
background: $primary-color; | ||
color: white; | ||
text-align: center; | ||
} |
43 changes: 43 additions & 0 deletions
43
examples/SSR/parcel-react-styled-components/app/HelloWorld2.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React, { Component } from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
import './codeSplitAssets/NyanCat.css'; | ||
import Go from './codeSplitAssets/NyanCat.js'; | ||
import importedComponent from "react-imported-component"; | ||
|
||
const HelloWorld3 = importedComponent(() => import('./HelloWorld3')); | ||
|
||
export default class Nyan extends Component { | ||
|
||
componentDidMount() { | ||
Go(); | ||
} | ||
|
||
render() { | ||
return <div> | ||
<h1 className="hello-world">Hello world 2!</h1> | ||
<p style={{ textAlign: 'center' }}> | ||
This is a code-split component. | ||
<br /> | ||
<Link to="/">Click here</Link> to see an ordinary component. | ||
</p> | ||
<div className="wrapper"> | ||
<div className="rainbow"> | ||
<span></span> | ||
</div> | ||
<div className="nyan-cat"> | ||
<div className="feet"></div> | ||
<div className="tail"> | ||
<span></span> | ||
</div> | ||
<div className="body"></div> | ||
<div className="head"></div> | ||
</div> | ||
<div className="stars"> | ||
|
||
</div> | ||
</div> | ||
and nested cat.... | ||
<HelloWorld3 /> | ||
</div> | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
examples/SSR/parcel-react-styled-components/app/HelloWorld3.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React, {Component} from 'react'; | ||
import {Link} from 'react-router-dom'; | ||
import './codeSplitAssets/NyanCat.css'; | ||
import Go from './codeSplitAssets/NyanCat.js'; | ||
|
||
export default class Nyan extends Component { | ||
|
||
componentDidMount() { | ||
Go(); | ||
} | ||
|
||
render() { | ||
return <div style={{position:'absolute',top:'500px'}}> | ||
I am async cat | ||
<div className="wrapper"> | ||
<div className="rainbow"> | ||
<span></span> | ||
</div> | ||
<div className="nyan-cat"> | ||
<div className="feet"></div> | ||
<div className="tail"> | ||
<span></span> | ||
</div> | ||
<div className="body"></div> | ||
<div className="head"></div> | ||
</div> | ||
<div className="stars"> | ||
|
||
</div> | ||
</div> | ||
</div> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Entry point for the browser | ||
// Start your React application and add the required containers | ||
// Here we have <BrowserRouter /> for react-router | ||
|
||
import 'react-hot-loader'; | ||
import {rehydrateMarks} from 'react-imported-component'; | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import {BrowserRouter} from 'react-router-dom'; | ||
import imp from './imp'; | ||
|
||
import App from './App'; | ||
|
||
const element = document.getElementById('app'); | ||
const app = ( | ||
<BrowserRouter> | ||
<App/> | ||
</BrowserRouter> | ||
); | ||
|
||
const TM = 1000; | ||
|
||
console.log('waiting'); | ||
setTimeout(function () { | ||
// rehydrate the bundle marks | ||
console.log('loading'); | ||
rehydrateMarks().then(() => { | ||
console.log('loaded...'); | ||
setTimeout(function () { | ||
console.log('rendering'); | ||
// In production, we want to hydrate instead of render | ||
// because of the server-rendering | ||
if (1 || process.env.NODE_ENV === 'production') { | ||
ReactDOM.hydrate(app, element); | ||
} else { | ||
ReactDOM.render(app, element); | ||
} | ||
}, TM); | ||
}); | ||
}, TM); | ||
|
||
// Hot reload is that easy with Parcel | ||
if (module.hot) { | ||
module.hot.accept(); | ||
} |
Oops, something went wrong.