├── .eslintrc.json
├── .gitignore
├── .vscode
├── extensions.json
└── settings.json
├── LICENSE
├── README.md
├── build-global-css.mjs
├── package-lock.json
├── package.json
├── postcss.config.js
├── rollup.config.js
├── src
├── client.js
├── components
│ └── ExampleComponent.svelte
├── global.pcss
├── routes
│ ├── _error.svelte
│ ├── _layout.svelte
│ └── index.svelte
├── server.js
├── service-worker.js
└── template.html
├── static
├── apple-touch-icon-180.png
├── favicon.png
├── logo-192.png
├── logo-512.png
├── manifest.json
└── screenshot-1.png
├── svelte.config.js
└── tailwind.config.js
/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": [
3 | "eslint:recommended",
4 | "airbnb-base"
5 | ],
6 | "parserOptions": {
7 | "ecmaVersion": 11,
8 | "sourceType": "module"
9 | },
10 | "env": {
11 | "node": true,
12 | "browser": true,
13 | "es2020": true
14 | },
15 | "rules": {
16 | "class-methods-use-this": "off",
17 | "import/prefer-default-export": "off",
18 | "import/no-extraneous-dependencies": "off",
19 | "indent": [
20 | "error",
21 | "tab"
22 | ],
23 | "no-console": "off",
24 | "no-tabs": [
25 | "error",
26 | {
27 | "allowIndentationTabs": true
28 | }
29 | ],
30 | "no-unused-vars": [
31 | "error",
32 | {
33 | "argsIgnorePattern": "^_"
34 | }
35 | ],
36 | "quotes": [
37 | "error",
38 | "double"
39 | ]
40 | },
41 | "overrides": [
42 | {
43 | "files": [
44 | "*.svelte"
45 | ],
46 | "plugins": [
47 | "svelte3"
48 | ],
49 | "processor": "svelte3/svelte3",
50 | "rules": {
51 | "import/first": "off",
52 | "import/no-duplicates": "off",
53 | "import/no-mutable-exports": "off",
54 | "import/no-mutable-unresolved": "off",
55 | "no-multiple-empty-lines": "off",
56 | "no-undef": "off",
57 | "no-unused-vars": "off"
58 | }
59 | }
60 | ]
61 | }
62 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ._*
2 | .DS_Store
3 | /.history/
4 | /node_modules/
5 | __sapper__/
6 | /src/node_modules/@sapper/
7 | /static/global.css
8 | /static/global.css.map
9 |
--------------------------------------------------------------------------------
/.vscode/extensions.json:
--------------------------------------------------------------------------------
1 | {
2 | "recommendations": [
3 | "bradlc.vscode-tailwindcss",
4 | "dbaeumer.vscode-eslint",
5 | "svelte.svelte-vscode"
6 | ]
7 | }
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "editor.codeActionsOnSave": {
3 | "source.fixAll": true
4 | },
5 | "[javascript]": {
6 | "editor.defaultFormatter": "dbaeumer.vscode-eslint"
7 | },
8 | "eslint.format.enable": true,
9 | "eslint.lintTask.enable": true,
10 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Jacob Babich
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
🌐 Sapper with PostCSS project base
2 |
3 | ## ❓ What is this?
4 | This is an extension to the [official Sapper Rollup template](https://github.com/sveltejs/sapper-template-rollup) with support for PostCSS inside Svelte components. You are also recommended to check out [@nhristov's similar template](https://github.com/nhristov/sapper-template-rollup).
5 |
6 | - [Sapper for Svelte](https://sapper.svelte.dev/)
7 | - [Official VS Code Extension](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode)
8 | - [PostCSS](https://postcss.org/)
9 | - [Tailwind CSS](https://tailwindcss.com/)
10 | - [Official VS Code Extension](https://marketplace.visualstudio.com/items?itemName=bradlc.vscode-tailwindcss)
11 | - [postcss-import](https://github.com/postcss/postcss-import)
12 | - [PurgeCSS](https://www.purgecss.com/)
13 | - [CSSNano](https://cssnano.co/)
14 | - Inside Svelte components, thanks to [`svelte-preprocess`](https://github.com/kaisermann/svelte-preprocess)
15 | - [Progressive Web App (PWA)](https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps) best practices set up
16 | - [`manifest.json`](https://developer.mozilla.org/en-US/docs/Web/Manifest)'s most important fields filled out
17 | - High [Lighthouse](https://developers.google.com/web/tools/lighthouse) audit score
18 | - [ESLint](https://eslint.org/)
19 | - [VS Code Extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
20 | - `eslint:fix` package script
21 |
22 | If you're looking for something with much, much more bundled in, check out [my opinionated project base](https://github.com/babichjacob/sapper-firebase-typescript-graphql-tailwindcss-actions-template).
23 |
24 | ## 🧭 Project Status
25 | **This project base will continue to be maintained** [until SvelteKit is ready](https://svelte.dev/blog/whats-the-deal-with-sveltekit).
26 |
27 | Once you are prepared to migrate, check out the [Svelte Adders](https://github.com/babichjacob/svelte-adders) project for information about how to recreate this project base's functionality. You should specifically look at [svelte-add-postcss](https://github.com/babichjacob/svelte-add-postcss) and [svelte-add-tailwindcss](https://github.com/babichjacob/svelte-add-tailwindcss).
28 |
29 | **Read on to use this project base today:**
30 |
31 | ## 📋 Copy
32 | Choose either to clone or fork depending on your preference.
33 |
34 | ### 🐑 Clone
35 | ```sh
36 | git clone https://github.com/babichjacob/sapper-postcss-template
37 | ```
38 |
39 | ### 🍴 Fork
40 | Click the `Use this template` button on [this project's GitHub page](https://github.com/babichjacob/sapper-postcss-template).
41 |
42 | ### ⬇️ Install Dependencies
43 | You need to be using version 14.15 or higher of Node.
44 |
45 | ```sh
46 | cd sapper-postcss-template
47 | npm install # pnpm also works
48 | ```
49 |
50 | ## 🛠 Usage
51 |
52 | ### 🧪 Development
53 | ```sh
54 | npm run dev
55 | ```
56 |
57 | ### 🔨 Building for Production
58 | ```sh
59 | npm run prod
60 | ```
61 |
62 | ### 📦 Exporting a Static Site
63 | ```sh
64 | npm run export
65 | ```
66 |
67 | ## ⚙ Configuration
68 |
69 | ### 💨 Optionally removing Tailwind CSS (and PurgeCSS)
70 | 1. Remove all Tailwind imports in the `src/global.pcss` file
71 | 2. Remove these lines in `postcss.config.js`:
72 | 1. ```js
73 | const tailwindcss = require("tailwindcss");
74 | ```
75 | 3. ```js
76 | const tailwindcssConfig = require("./tailwind.config");
77 | ```
78 | 3. ```js
79 | tailwindcss(tailwindcssConfig),
80 | ```
81 | 3. Delete the `tailwind.config.js` file
82 | 4. Uninstall the `tailwindcss` package
83 |
84 | ### ⚡ Web app
85 | Many of the fields in `static/manifest.json` (`short_name`, `name`, `description`, `categories`, `theme_color`, and `background_color`) are filled with demonstrative values that won't match your site. Similarly, you've got to take new screenshots to replace the included `static/screenshot-1.png` file. If you want, you can add [app shortcut definitions for "add to home screen" on Android](https://web.dev/app-shortcuts/#define-app-shortcuts-in-the-web-app-manifest). Once you change `theme_color`, update the `meta name="theme-color"` tag in `src/template.html` to match.
86 |
87 | The [Apple touch icon](https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/ConfiguringWebApplications/ConfiguringWebApplications.html), favicon, and `logo-` files (also all in the `static` directory) are created by placing the logo within a "safe area" centered circle that takes up 80% of the canvas's dimension. For instance, the constraining circle in `logo-512.png` is 512 × 0.80 = 409.6 ≈ 410 pixels wide and tall.
88 |
89 | ### 🗺 Source maps
90 | This project base comes with [source maps](https://blog.teamtreehouse.com/introduction-source-maps) enabled during development and disabled during production (and exports) for the best compromise between performance and developer experience. You can change this behavior through the `sourcemap` variable in `rollup.config.js`.
91 |
92 | ## 😵 Help! I have a question
93 |
94 | [Create an issue](https://github.com/babichjacob/sapper-postcss-template/issues/new) and I'll try to help.
95 |
96 | ## 😡 Fix! There is something that needs improvement
97 |
98 | [Create an issue](https://github.com/babichjacob/sapper-postcss-template/issues/new) or [pull request](https://github.com/babichjacob/sapper-postcss-template/pulls) and I'll try to fix.
99 |
100 | I'm sorry, because of my skill level and the fragility of (the combination of) some of these tools, there are likely to be problems in this project. Thank you for bringing them to my attention or fixing them for me.
101 |
102 | ## 📄 License
103 |
104 | MIT
105 |
106 | ---
107 |
108 | _This README was generated with ❤️ by [readme-md-generator](https://github.com/kefranabg/readme-md-generator)_
109 |
--------------------------------------------------------------------------------
/build-global-css.mjs:
--------------------------------------------------------------------------------
1 | import fs from "fs";
2 | import postcss from "postcss";
3 | // eslint-disable-next-line import/extensions
4 | import postcssConfig from "./postcss.config.js";
5 |
6 | const { readFile, unlink, writeFile } = fs.promises;
7 |
8 | const main = async () => {
9 | let sourcemap = process.argv[process.argv.length - 1];
10 | if (sourcemap === "true") sourcemap = true;
11 | else if (sourcemap === "false") sourcemap = false;
12 |
13 | const pcss = await readFile("src/global.pcss");
14 |
15 | const result = await postcss(postcssConfig.plugins).process(pcss, { from: "src/global.pcss", to: "static/global.css", map: sourcemap ? { inline: sourcemap === "inline" } : false });
16 |
17 | await writeFile("static/global.css", result.css);
18 |
19 | if (result.map) await writeFile("static/global.css.map", result.map.toString());
20 | else {
21 | try {
22 | await unlink("static/global.css.map");
23 | } catch (err) {
24 | if (err.code !== "ENOENT") {
25 | throw err;
26 | }
27 | }
28 | }
29 | };
30 |
31 | main();
32 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "sapper-postcss-template",
3 | "description": "A template that includes Sapper for Svelte and PostCSS preprocessing with Tailwind CSS",
4 | "keywords": [
5 | "sapper",
6 | "eslint",
7 | "postcss",
8 | "purgecss",
9 | "svelte",
10 | "tailwindcss",
11 | "cssnano"
12 | ],
13 | "homepage": "https://github.com/babichjacob/sapper-postcss-template",
14 | "repository": {
15 | "type": "git",
16 | "url": "https://github.com/babichjacob/sapper-postcss-template.git"
17 | },
18 | "license": "MIT",
19 | "version": "2020.12.12",
20 | "scripts": {
21 | "eslint": "eslint",
22 | "eslint:fix": "eslint --fix ./*.js ./src/*.js ./src/routes/**/*.svelte ./src/components/**/*.svelte",
23 | "dev": "sapper dev",
24 | "build": "cross-env NODE_ENV=production sapper build --legacy",
25 | "prod": "npm run build",
26 | "export": "cross-env NODE_ENV=production sapper export --legacy",
27 | "start": "node __sapper__/build"
28 | },
29 | "dependencies": {
30 | "compression": "^1.7.4",
31 | "express": "^4.17.1",
32 | "sirv": "^1.0.10"
33 | },
34 | "devDependencies": {
35 | "@babel/core": "^7.12.10",
36 | "@babel/plugin-syntax-dynamic-import": "^7.8.3",
37 | "@babel/plugin-transform-runtime": "^7.12.10",
38 | "@babel/preset-env": "^7.12.10",
39 | "@babel/runtime": "^7.12.5",
40 | "@rollup/plugin-babel": "^5.2.2",
41 | "@rollup/plugin-commonjs": "^17.0.0",
42 | "@rollup/plugin-node-resolve": "^10.0.0",
43 | "@rollup/plugin-replace": "^2.3.4",
44 | "cross-env": "^7.0.3",
45 | "cssnano": "^4.1.10",
46 | "eslint": "^7.15.0",
47 | "eslint-config-airbnb-base": "^14.2.1",
48 | "eslint-plugin-import": "^2.22.1",
49 | "eslint-plugin-svelte3": "^2.7.3",
50 | "kleur": "^4.1.3",
51 | "postcss": "^8.2.1",
52 | "postcss-import": "^13.0.0",
53 | "rollup": "^2.34.2",
54 | "rollup-plugin-svelte": "^7.0.0",
55 | "rollup-plugin-terser": "^7.0.2",
56 | "sapper": "^0.28.10",
57 | "svelte": "^3.31.0",
58 | "svelte-preprocess": "^4.6.1",
59 | "tailwindcss": "^2.0.2"
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/postcss.config.js:
--------------------------------------------------------------------------------
1 | const cssnano = require("cssnano");
2 | const postcssImport = require("postcss-import");
3 | const tailwindcss = require("tailwindcss");
4 | const tailwindcssConfig = require("./tailwind.config");
5 |
6 | const mode = process.env.NODE_ENV;
7 | const dev = mode === "development";
8 |
9 | module.exports = {
10 | plugins: [
11 | postcssImport,
12 |
13 | tailwindcss(tailwindcssConfig),
14 |
15 | // Plugins for polyfills and the like (such as postcss-preset-env) should generally go here
16 | // but a few have to run *before* Tailwind
17 |
18 | !dev && cssnano({
19 | preset: [
20 | "default",
21 | { discardComments: { removeAll: true } },
22 | ],
23 | }),
24 | ].filter(Boolean),
25 | };
26 |
--------------------------------------------------------------------------------
/rollup.config.js:
--------------------------------------------------------------------------------
1 | import { spawn } from "child_process";
2 | import { performance } from "perf_hooks";
3 | import resolve from "@rollup/plugin-node-resolve";
4 | import replace from "@rollup/plugin-replace";
5 | import commonjs from "@rollup/plugin-commonjs";
6 | import svelte from "rollup-plugin-svelte";
7 | import babel from "@rollup/plugin-babel";
8 | import colors from "kleur";
9 | import { terser } from "rollup-plugin-terser";
10 | import config from "sapper/config/rollup";
11 | import pkg from "./package.json";
12 |
13 | const { createPreprocessors } = require("./svelte.config.js");
14 |
15 | const mode = process.env.NODE_ENV;
16 | const dev = mode === "development";
17 | const sourcemap = dev ? "inline" : false;
18 | const legacy = !!process.env.SAPPER_LEGACY_BUILD;
19 |
20 | const preprocess = createPreprocessors({ sourceMap: !!sourcemap });
21 |
22 | // Changes in these files will trigger a rebuild of the global CSS
23 | const globalCSSWatchFiles = ["postcss.config.js", "tailwind.config.js", "src/global.pcss"];
24 |
25 | // Workaround for https://github.com/sveltejs/sapper/issues/1266
26 | const onwarn = (warning, _onwarn) => (warning.code === "CIRCULAR_DEPENDENCY" && /[/\\]@sapper[/\\]/.test(warning.message)) || console.warn(warning.toString());
27 |
28 | export default {
29 | client: {
30 | input: config.client.input(),
31 | output: { ...config.client.output(), sourcemap },
32 | plugins: [
33 | replace({
34 | "process.browser": true,
35 | "process.env.NODE_ENV": JSON.stringify(mode),
36 | }),
37 | svelte({
38 | compilerOptions: {
39 | dev,
40 | hydratable: true,
41 | },
42 | emitCss: true,
43 | preprocess,
44 | }),
45 | resolve({
46 | browser: true,
47 | dedupe: ["svelte"],
48 | }),
49 | commonjs({
50 | sourceMap: !!sourcemap,
51 | }),
52 |
53 | legacy && babel({
54 | extensions: [".js", ".mjs", ".html", ".svelte"],
55 | babelHelpers: "runtime",
56 | exclude: ["node_modules/@babel/**"],
57 | presets: [
58 | ["@babel/preset-env", {
59 | targets: "> 0.25%, not dead",
60 | }],
61 | ],
62 | plugins: [
63 | "@babel/plugin-syntax-dynamic-import",
64 | ["@babel/plugin-transform-runtime", {
65 | useESModules: true,
66 | }],
67 | ],
68 | }),
69 |
70 | !dev && terser({
71 | module: true,
72 | }),
73 |
74 | (() => {
75 | let builder;
76 | let rebuildNeeded = false;
77 |
78 | const buildGlobalCSS = () => {
79 | if (builder) {
80 | rebuildNeeded = true;
81 | return;
82 | }
83 | rebuildNeeded = false;
84 | const start = performance.now();
85 |
86 | try {
87 | builder = spawn("node", ["--experimental-modules", "--unhandled-rejections=strict", "build-global-css.mjs", sourcemap]);
88 | builder.stdout.pipe(process.stdout);
89 | builder.stderr.pipe(process.stderr);
90 |
91 | builder.on("close", (code) => {
92 | if (code === 0) {
93 | const elapsed = parseInt(performance.now() - start, 10);
94 | console.log(`${colors.bold().green("✔ global css")} (src/global.pcss → static/global.css${sourcemap === true ? " + static/global.css.map" : ""}) ${colors.gray(`(${elapsed}ms)`)}`);
95 | } else if (code !== null) {
96 | if (dev) {
97 | console.error(`global css builder exited with code ${code}`);
98 | console.log(colors.bold().red("✗ global css"));
99 | } else {
100 | throw new Error(`global css builder exited with code ${code}`);
101 | }
102 | }
103 |
104 | builder = undefined;
105 |
106 | if (rebuildNeeded) {
107 | console.log(`\n${colors.bold().italic().cyan("something")} changed. rebuilding...`);
108 | buildGlobalCSS();
109 | }
110 | });
111 | } catch (err) {
112 | console.log(colors.bold().red("✗ global css"));
113 | console.error(err);
114 | }
115 | };
116 |
117 | return {
118 | name: "build-global-css",
119 | buildStart() {
120 | buildGlobalCSS();
121 | globalCSSWatchFiles.forEach((file) => this.addWatchFile(file));
122 | },
123 | generateBundle: buildGlobalCSS,
124 | };
125 | })(),
126 | ],
127 |
128 | preserveEntrySignatures: false,
129 | onwarn,
130 | },
131 |
132 | server: {
133 | input: config.server.input(),
134 | output: { ...config.server.output(), sourcemap },
135 | plugins: [
136 | replace({
137 | "process.browser": false,
138 | "process.env.NODE_ENV": JSON.stringify(mode),
139 | }),
140 | svelte({
141 | compilerOptions: {
142 | dev,
143 | generate: "ssr",
144 | },
145 | preprocess,
146 | }),
147 | resolve({
148 | dedupe: ["svelte"],
149 | }),
150 | commonjs({
151 | sourceMap: !!sourcemap,
152 | }),
153 | ],
154 | external: Object.keys(pkg.dependencies).concat(
155 | require("module").builtinModules || Object.keys(process.binding("natives")), // eslint-disable-line global-require
156 | ),
157 |
158 | preserveEntrySignatures: "strict",
159 | onwarn,
160 | },
161 |
162 | serviceworker: {
163 | input: config.serviceworker.input(),
164 | output: { ...config.serviceworker.output(), sourcemap },
165 | plugins: [
166 | resolve(),
167 | replace({
168 | "process.browser": true,
169 | "process.env.NODE_ENV": JSON.stringify(mode),
170 | }),
171 | commonjs({
172 | sourceMap: !!sourcemap,
173 | }),
174 | !dev && terser(),
175 | ],
176 |
177 | preserveEntrySignatures: false,
178 | onwarn,
179 | },
180 | };
181 |
--------------------------------------------------------------------------------
/src/client.js:
--------------------------------------------------------------------------------
1 | import * as sapper from "@sapper/app";
2 |
3 | sapper.start({
4 | target: document.querySelector("#sapper"),
5 | });
6 |
--------------------------------------------------------------------------------
/src/components/ExampleComponent.svelte:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 |
9 | {paragraph}
10 |
--------------------------------------------------------------------------------
/src/global.pcss:
--------------------------------------------------------------------------------
1 | @import "tailwindcss/base";
2 | /* @import "./base.pcss"; */
3 |
4 | @import "tailwindcss/components";
5 | /* @import "./components.pcss"; */
6 |
7 | @import "tailwindcss/utilities";
8 | /* @import "./utilities.pcss"; */
9 |
--------------------------------------------------------------------------------
/src/routes/_error.svelte:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 | {error.message}
11 | {status}
12 |
13 |
14 | {#if dev && error.stack}
15 | {error.stack}
16 | {/if}
17 |
--------------------------------------------------------------------------------
/src/routes/_layout.svelte:
--------------------------------------------------------------------------------
1 |
4 |
5 |
19 |
20 |
21 |
22 | {path ? path.charAt(0).toUpperCase() + path.slice(1) : "Index"}
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/routes/index.svelte:
--------------------------------------------------------------------------------
1 |
4 |
5 |
10 |
11 |
12 |
15 |
16 |
--------------------------------------------------------------------------------
/src/server.js:
--------------------------------------------------------------------------------
1 | import sirv from "sirv";
2 | import Express from "express";
3 | import compression from "compression";
4 | import * as sapper from "@sapper/server";
5 |
6 | const { PORT, NODE_ENV } = process.env;
7 | const dev = NODE_ENV === "development";
8 |
9 | Express()
10 | .use(
11 | compression({ threshold: 0 }),
12 | sirv("static", { dev }),
13 | sapper.middleware(),
14 | )
15 | .listen(PORT, (err) => {
16 | if (err) console.log("error", err);
17 | });
18 |
--------------------------------------------------------------------------------
/src/service-worker.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-restricted-globals */
2 | import {
3 | files, routes, shell, timestamp, // eslint-disable-line no-unused-vars
4 | } from "@sapper/service-worker"; // eslint-disable-line import/no-unresolved
5 |
6 | const ASSETS = `cache${timestamp}`;
7 |
8 | // `shell` is an array of all the files generated by the bundler,
9 | // `files` is an array of everything in the `static` directory
10 | const toCache = shell.concat(files);
11 | const cached = new Set(toCache);
12 |
13 | self.addEventListener("install", (event) => { // eslint-disable-line no-shadow,no-inline-comments,line-comment-position
14 | event.waitUntil(
15 | caches
16 | .open(ASSETS)
17 | .then((cache) => cache.addAll(toCache))
18 | .then(() => {
19 | self.skipWaiting();
20 | }),
21 | );
22 | });
23 |
24 | self.addEventListener("activate", (event) => { // eslint-disable-line no-shadow,no-inline-comments,line-comment-position
25 | event.waitUntil(
26 | caches.keys().then(async (keys) => {
27 | // Delete old caches
28 | for (const key of keys) { // eslint-disable-line no-restricted-syntax
29 | if (key !== ASSETS) await caches.delete(key); // eslint-disable-line no-await-in-loop
30 | }
31 |
32 | self.clients.claim();
33 | }),
34 | );
35 | });
36 |
37 | self.addEventListener("fetch", (event) => { // eslint-disable-line no-shadow,no-inline-comments,line-comment-position
38 | if (event.request.method !== "GET" || event.request.headers.has("range")) return;
39 |
40 | const url = new URL(event.request.url);
41 |
42 | // Don't try to handle e.g. data: URIs
43 | if (!url.protocol.startsWith("http")) return;
44 |
45 | // Ignore dev server requests
46 | if (url.hostname === self.location.hostname && url.port !== self.location.port) return;
47 |
48 | // Always serve static files and bundler-generated assets from cache
49 | if (url.host === self.location.host && cached.has(url.pathname)) {
50 | event.respondWith(caches.match(event.request));
51 | return;
52 | }
53 |
54 | // For pages, you might want to serve a shell `service-worker-index.html` file,
55 | // Which Sapper has generated for you. It's not right for every
56 | // App, but if it's right for yours then uncomment this section
57 | /*
58 | If (url.origin === self.origin && routes.find(route => route.pattern.test(url.pathname))) {
59 | event.respondWith(caches.match('/service-worker-index.html'));
60 | return;
61 | }
62 | */
63 |
64 | if (event.request.cache === "only-if-cached") return;
65 |
66 | // For everything else, try the network first, falling back to
67 | // Cache if the user is offline. (If the pages never change, you
68 | // Might prefer a cache-first approach to a network-first one.)
69 | event.respondWith(
70 | caches
71 | .open(`offline${timestamp}`)
72 | .then(async (cache) => {
73 | try {
74 | const response = await fetch(event.request);
75 | cache.put(event.request, response.clone());
76 | return response;
77 | } catch (err) {
78 | const response = await cache.match(event.request);
79 | if (response) return response;
80 |
81 | throw err;
82 | }
83 | }),
84 | );
85 | });
86 |
--------------------------------------------------------------------------------
/src/template.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | %sapper.base%
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
19 | %sapper.styles%
20 |
21 |
23 | %sapper.head%
24 |
25 |
26 |
27 |
28 | %sapper.html%
29 |
30 |
31 | %sapper.scripts%
32 |
33 |
34 |
--------------------------------------------------------------------------------
/static/apple-touch-icon-180.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/babichjacob/sapper-postcss-template/aa5c4db693f9b11bc9a6412e067f897216b072cc/static/apple-touch-icon-180.png
--------------------------------------------------------------------------------
/static/favicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/babichjacob/sapper-postcss-template/aa5c4db693f9b11bc9a6412e067f897216b072cc/static/favicon.png
--------------------------------------------------------------------------------
/static/logo-192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/babichjacob/sapper-postcss-template/aa5c4db693f9b11bc9a6412e067f897216b072cc/static/logo-192.png
--------------------------------------------------------------------------------
/static/logo-512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/babichjacob/sapper-postcss-template/aa5c4db693f9b11bc9a6412e067f897216b072cc/static/logo-512.png
--------------------------------------------------------------------------------
/static/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "Sapper + PostCSS",
3 | "name": "Sapper with PostCSS project base",
4 | "description": "A template that includes Svelte with Sapper and PostCSS preprocessing with Tailwind CSS",
5 | "categories": ["personalization", "productivity"],
6 | "lang": "en-US",
7 | "dir": "ltr",
8 | "icons": [
9 | {
10 | "src": "logo-192.png",
11 | "sizes": "192x192",
12 | "type": "image/png",
13 | "purpose": "any maskable"
14 | },
15 | {
16 | "src": "logo-512.png",
17 | "sizes": "512x512",
18 | "type": "image/png",
19 | "purpose": "any maskable"
20 | }
21 | ],
22 | "start_url": "/",
23 | "display": "minimal-ui",
24 | "background_color": "#FFFFFF",
25 | "theme_color": "#3F83F8",
26 | "screenshots": [
27 | {
28 | "src": "screenshot-1.png",
29 | "sizes": "1280x720",
30 | "type": "image/png"
31 | }
32 | ]
33 | }
34 |
--------------------------------------------------------------------------------
/static/screenshot-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/babichjacob/sapper-postcss-template/aa5c4db693f9b11bc9a6412e067f897216b072cc/static/screenshot-1.png
--------------------------------------------------------------------------------
/svelte.config.js:
--------------------------------------------------------------------------------
1 | const sveltePreprocess = require("svelte-preprocess");
2 | const postcss = require("./postcss.config");
3 |
4 | const createPreprocessors = ({ sourceMap }) => [
5 | sveltePreprocess({
6 | sourceMap,
7 | defaults: {
8 | style: "postcss",
9 | },
10 | postcss,
11 | }),
12 | // You could have more preprocessors, like mdsvex
13 | ];
14 |
15 | module.exports = {
16 | createPreprocessors,
17 | // Options for `svelte-check` and the VS Code extension
18 | preprocess: createPreprocessors({ sourceMap: true }),
19 | };
20 |
--------------------------------------------------------------------------------
/tailwind.config.js:
--------------------------------------------------------------------------------
1 | const { tailwindExtractor } = require("tailwindcss/lib/lib/purgeUnusedStyles");
2 |
3 | module.exports = {
4 | purge: {
5 | content: [
6 | "./src/**/*.html",
7 | "./src/**/*.svelte",
8 | ],
9 | options: {
10 | defaultExtractor: (content) => [
11 | // This is an internal Tailwind function that we're not supposed to be allowed to use
12 | // So if this stops working, please open an issue at
13 | // https://github.com/babichjacob/sapper-postcss-template/issues
14 | // rather than bothering Tailwind Labs about it
15 | ...tailwindExtractor(content),
16 | // Match Svelte class: directives (https://github.com/tailwindlabs/tailwindcss/discussions/1731)
17 | ...[...content.matchAll(/(?:class:)*([\w\d-/:%.]+)/gm)].map(([_match, group, ..._rest]) => group),
18 | ],
19 | keyframes: true,
20 | },
21 | },
22 | theme: {
23 | extend: {},
24 | },
25 | variants: {
26 | extend: {},
27 | },
28 | plugins: [],
29 | };
30 |
--------------------------------------------------------------------------------