Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved Preact integration #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples/snowpack-preact/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.build
build
web_modules
node_modules
4 changes: 4 additions & 0 deletions examples/snowpack-preact/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
21 changes: 21 additions & 0 deletions examples/snowpack-preact/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Fred K. Schott

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.
27 changes: 27 additions & 0 deletions examples/snowpack-preact/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# New Project

> ✨ Bootstrapped with Create Snowpack App (CSA).

## Available Scripts

### npm start

Runs the app in the development mode.
Open http://localhost:8080 to view it in the browser.

The page will reload if you make edits.
You will also see any lint errors in the console.

### npm test

Launches the test runner in the interactive watch mode.
See the section about running tests for more information.

### npm run build

Builds the app for production to the `build/` folder.
It correctly bundles Preact in production mode and optimizes the build for the best performance.

### Q: What about Eject?

No eject needed! Snowpack guarantees zero lock-in, and CSA strives for the same.
23 changes: 23 additions & 0 deletions examples/snowpack-preact/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"scripts": {
"start": "snowpack dev",
"build": "snowpack build",
"test": "web-test-runner \"src/**/*.test.jsx\"",
"format": "prettier --write \"src/**/*.{js,jsx}\"",
"lint": "prettier --check \"src/**/*.{js,jsx}\""
},
"dependencies": {
"@pago/reactive": "^0.2.1",
"preact": "^10.5.0"
},
"devDependencies": {
"@prefresh/snowpack": "^2.0.1",
"@snowpack/plugin-dotenv": "^2.0.4",
"@snowpack/web-test-runner-plugin": "^0.1.4",
"@testing-library/preact": "^2.0.0",
"@web/test-runner": "^0.9.7",
"chai": "^4.2.0",
"prettier": "^2.0.5",
"snowpack": "^2.17.1"
}
}
Binary file added examples/snowpack-preact/public/favicon.ico
Binary file not shown.
25 changes: 25 additions & 0 deletions examples/snowpack-preact/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="Web site created using create-snowpack-app" />
<title>Snowpack App</title>
</head>
<body>
<div id="root"></div>
<noscript>You need to enable JavaScript to run this app.</noscript>
<script type="module" src="/_dist_/index.js"></script>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
3 changes: 3 additions & 0 deletions examples/snowpack-preact/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
28 changes: 28 additions & 0 deletions examples/snowpack-preact/snowpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/** @type {import("snowpack").SnowpackUserConfig } */
module.exports = {
mount: {
public: '/',
src: '/_dist_',
},
plugins: ['@snowpack/plugin-dotenv', '@prefresh/snowpack'],
install: [
/* ... */
],
installOptions: {
/* ... */
},
devOptions: {
/* ... */
},
buildOptions: {
/* ... */
},
proxy: {
/* ... */
},

alias: {
/* ... */
react: 'preact/compat',
},
};
41 changes: 41 additions & 0 deletions examples/snowpack-preact/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.App {
text-align: center;
}
.App code {
background: #FFF3;
padding: 4px 8px;
border-radius: 4px;
}
.App p {
margin: 0.4rem;
}

.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}

.App-link {
color: #61dafb;
}

.App-logo {
height: 36vmin;
pointer-events: none;
margin-bottom: 3rem;
animation: App-logo-spin infinite 1.6s ease-in-out alternate;
}
@keyframes App-logo-spin {
from {
transform: scale(1);
}
to {
transform: scale(1.06);
}
}
40 changes: 40 additions & 0 deletions examples/snowpack-preact/src/App.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { h } from 'preact';
import { ref, effect } from '@pago/reactive';
import logo from './logo.png';
import './App.css';

function App() {
// Create the count state.
const count = ref(0);
// Create the counter (+1 every second).
effect(onInvalidate => {
const timer = setInterval(() => count.current++, 1000);
onInvalidate(() => clearInterval(timer));
});
// Return the App component.
return () => (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.jsx</code> and save to reload.
</p>
<p>
Page has been open for <code>{count.current}</code> seconds.
</p>
<p>
<a
className="App-link"
href="https://preactjs.com"
target="_blank"
rel="noopener noreferrer"
>
Learn Preact
</a>
</p>
</header>
</div>
);
}

export default App;
12 changes: 12 additions & 0 deletions examples/snowpack-preact/src/App.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { h } from 'preact';
import { render } from '@testing-library/preact';
import { expect } from 'chai';
import App from './App';

describe('<App>', () => {
it('renders learn react link', () => {
const { getByText } = render(<App />);
const linkElement = getByText(/learn preact/i);
expect(document.body.contains(linkElement));
});
});
13 changes: 13 additions & 0 deletions examples/snowpack-preact/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}
7 changes: 7 additions & 0 deletions examples/snowpack-preact/src/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { h, render } from 'preact';
import 'preact/devtools';
import '@pago/reactive/preact';
import App from './App.js';
import './index.css';

render(<App />, document.getElementById('root'));
Binary file added examples/snowpack-preact/src/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions examples/snowpack-preact/web-test-runner.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// NODE_ENV=test - Needed by "@snowpack/web-test-runner-plugin"
process.env.NODE_ENV = 'test';

module.exports = {
plugins: [require('@snowpack/web-test-runner-plugin')()],
};
Loading