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

Add snowpack #1

Merged
merged 1 commit into from
Oct 22, 2020
Merged
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
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Snowpack ❤️ Create-React-App

A stock CRA app modified to use [snowpack](https://snowpack.dev) during development for faster rebuilds.

See [the PR](https://github.com/pbeshai/cra-snowpack/pull/1/files) for all the changes.


---
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts
Expand Down Expand Up @@ -65,4 +73,4 @@ This section has moved here: https://facebook.github.io/create-react-app/docs/de

### `yarn build` fails to minify

This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
3 changes: 3 additions & 0 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["@babel/preset-react"]
}
16 changes: 12 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@snowpack/app-scripts-react": "^1.12.5",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "3.4.4"
"postcss-cli": "^7.1.2",
"postcss-flexbugs-fixes": "^4.2.1",
"postcss-import": "^12.0.1",
"postcss-normalize": "^9.0.0",
"postcss-preset-env": "^6.7.0",
"react": "^17.0.0",
"react-dom": "^17.0.0",
"react-scripts": "3.4.4",
"snowpack": "^2.15.1"
},
"scripts": {
"start": "react-scripts start",
"start": "snowpack dev --config snowpack.config.js",
"start:cra": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
Expand Down
18 changes: 18 additions & 0 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = (ctx) => {
return {
plugins: {
// need this to get relative @import "./Foo.css"; working
'postcss-import': { root: ctx.file.dirname },

// copied from create-react-app
'postcss-flexbugs-fixes': {},
'postcss-preset-env': {
autoprefixer: {
flexbox: 'no-2009',
},
stage: 3,
},
'postcss-normalize': {},
},
};
};
16 changes: 16 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>

<!--
add entry for snowpack, only used in dev, it is pruned in production.
-->
<script>
if ('%MODE%' === 'development') {
(function() {
console.log('[dev] injecting snowpack entry')
var snowpackEntryScript = document.createElement('script');
snowpackEntryScript.setAttribute('type', 'module');
snowpackEntryScript.setAttribute('src', '/_dist_/index.js');
document.head.appendChild(snowpackEntryScript);
}())
}
</script>

<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
Expand Down
36 changes: 36 additions & 0 deletions snowpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// read in packageJson for getting proxy
const packageJson = require('./package.json');

module.exports = {
extends: '@snowpack/app-scripts-react',

devOptions: {
port: 3000,
src: 'src',
bundle: false,
fallback: 'index.html',
},

installOptions: {
polyfillNode: true,
},

plugins: [
// use postcss to get relative imports working and to match CRA
[
'@snowpack/plugin-build-script',
{ cmd: 'postcss $FILE', input: ['.css'], output: ['.css'] },
],
],

// allow absolute imports e.g. `import Comp from 'src/components/Comp'`
// (similar to having baseUrl: "." in jsconfig.json)
alias: {
src: './src',
},

// optionally add in a proxy to /api
// proxy: {
// '/api': `${packageJson.proxy}/api`,
// },
};