-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit with blank sveltejs/component-template
- Loading branch information
0 parents
commit df4c5bb
Showing
5 changed files
with
84 additions
and
0 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,6 @@ | ||
.DS_Store | ||
node_modules | ||
yarn.lock | ||
package-lock.json | ||
index.js | ||
index.mjs |
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 @@ | ||
*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.svelte`. | ||
|
||
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.svelte`, which allows Svelte apps to import the source code directly, if they are using a bundler plugin like [rollup-plugin-svelte](https://github.com/sveltejs/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. |
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,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" | ||
] | ||
} |
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,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() | ||
] | ||
}; |
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 @@ | ||
<!-- your code here --> |