From a20b6f2a70eb1707d7a35e3c34aa699c96d2d82a Mon Sep 17 00:00:00 2001 From: Sveltecasts Date: Sat, 13 Jul 2019 17:21:16 +0200 Subject: [PATCH] init --- .gitignore | 6 ++++++ README.md | 33 +++++++++++++++++++++++++++++++++ package.json | 24 ++++++++++++++++++++++++ rollup.config.js | 20 ++++++++++++++++++++ src/index.svelte | 41 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 124 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 package.json create mode 100644 rollup.config.js create mode 100644 src/index.svelte diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..050b000 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.DS_Store +node_modules +yarn.lock +package-lock.json +index.js +index.mjs \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..71e531f --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ +*Psst — looking for an app template? Go here --> [sveltejs/template](https://github.com/sveltejs/template)* + +--- + +# component-template + +A base for building shareable Svelte components. Clone it with [degit](https://github.com/Rich-Harris/degit): + +```bash +npx degit sveltejs/component-template my-new-component +cd my-new-component +npm install # or yarn +``` + +Your component's source code lives in `src/index.html`. + +TODO + +* [ ] some firm opinions about the best way to test components +* [ ] update `degit` so that it automates some of the setup work + + +## Setting up + +* Run `npm init` (or `yarn init`) +* Replace this README with your own + + +## Consuming components + +Your package.json has a `"svelte"` field pointing to `src/index.html`, which allows Svelte apps to import the source code directly, if they are using a bundler plugin like [rollup-plugin-svelte](https://github.com/rollup/rollup-plugin-svelte) or [svelte-loader](https://github.com/sveltejs/svelte-loader) (where [`resolve.mainFields`](https://webpack.js.org/configuration/resolve/#resolve-mainfields) in your webpack config includes `"svelte"`). **This is recommended.** + +For everyone else, `npm run build` will bundle your component's source code into a plain JavaScript module (`index.mjs`) and a UMD script (`index.js`). This will happen automatically when you publish your component to npm, courtesy of the `prepublishOnly` hook in package.json. diff --git a/package.json b/package.json new file mode 100644 index 0000000..0a3b9a4 --- /dev/null +++ b/package.json @@ -0,0 +1,24 @@ +{ + "name": "SvelteComponent", + "svelte": "src/index.svelte", + "module": "index.mjs", + "main": "index.js", + "scripts": { + "build": "rollup -c", + "prepublishOnly": "npm run build" + }, + "devDependencies": { + "rollup": "^1.11.0", + "rollup-plugin-node-resolve": "^4.0.0", + "rollup-plugin-svelte": "^5.0.0", + "svelte": "^3.0.0" + }, + "keywords": [ + "svelte" + ], + "files": [ + "src", + "index.mjs", + "index.js" + ] +} diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000..eac15bc --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,20 @@ +import svelte from 'rollup-plugin-svelte'; +import resolve from 'rollup-plugin-node-resolve'; +import pkg from './package.json'; + +const name = pkg.name + .replace(/^(@\S+\/)?(svelte-)?(\S+)/, '$3') + .replace(/^\w/, m => m.toUpperCase()) + .replace(/-\w/g, m => m[1].toUpperCase()); + +export default { + input: 'src/index.svelte', + output: [ + { file: pkg.module, 'format': 'es' }, + { file: pkg.main, 'format': 'umd', name } + ], + plugins: [ + svelte(), + resolve() + ] +}; diff --git a/src/index.svelte b/src/index.svelte new file mode 100644 index 0000000..4973f90 --- /dev/null +++ b/src/index.svelte @@ -0,0 +1,41 @@ + + + +YT-Component VID: {videoId}
+