Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

docs: add information about "sideEffects"#10691

Merged
benmccann merged 17 commits intosveltejs:mainfromrossrobino:patch-1
Jun 19, 2024
Merged
Changes fromall commits
Commits
Show all changes
17 commits
Select commitHold shift + click to select a range
750a18f
docs: add information about "sideEffects"
rossrobinoSep 7, 2023
e9f0477
Update documentation/docs/30-advanced/70-packaging.md
rossrobinoSep 8, 2023
a5f042b
Update documentation/docs/30-advanced/70-packaging.md
rossrobinoSep 8, 2023
f7a0285
Update documentation/docs/30-advanced/70-packaging.md
rossrobinoSep 8, 2023
4974741
Update documentation/docs/30-advanced/70-packaging.md
rossrobinoOct 18, 2023
de56110
Update documentation/docs/30-advanced/70-packaging.md
benmccannJun 19, 2024
2a0e697
Update documentation/docs/30-advanced/70-packaging.md
benmccannJun 19, 2024
0ae5b81
Update 70-packaging.md
benmccannJun 19, 2024
37f681c
Update documentation/docs/30-advanced/70-packaging.md
benmccannJun 19, 2024
0c1d598
Update documentation/docs/30-advanced/70-packaging.md
benmccannJun 19, 2024
49a44c0
Update documentation/docs/30-advanced/70-packaging.md
benmccannJun 19, 2024
b1984e6
Update documentation/docs/30-advanced/70-packaging.md
benmccannJun 19, 2024
10ee8ba
Update documentation/docs/30-advanced/70-packaging.md
benmccannJun 19, 2024
c59a9e7
Update documentation/docs/30-advanced/70-packaging.md
benmccannJun 19, 2024
8ee1a8f
Update documentation/docs/30-advanced/70-packaging.md
benmccannJun 19, 2024
b580cb2
Update documentation/docs/30-advanced/70-packaging.md
benmccannJun 19, 2024
5bc1a85
Update documentation/docs/30-advanced/70-packaging.md
benmccannJun 19, 2024
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
24 changes: 24 additions & 0 deletionsdocumentation/docs/30-advanced/70-packaging.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -126,6 +126,30 @@ This is a legacy field that enabled tooling to recognise Svelte component librar
}
```

### sideEffects

The `sideEffects` field in `package.json` is used by bundlers to determine if a module may contain code that has side-effects. A module is considered to have side-effects if it makes changes that are observable from other scripts outside the module when it's imported. For example, side-effects include modifying global variables or the prototype of built-in JavaScript objects. Because a side-effect could potentially affect the behavior of other parts of the application, these files/modules will be included in the final bundle regardless of whether their exports are used in the application. It is a best practice to avoid side-effects in your code.

Setting the `sideEffects` field in `package.json` can help the bundler to be more aggressive in eliminating unused exports from the final bundle, a process known as tree-shaking. This results in smaller and more efficient bundles. Different bundlers handle `sideEffects` in various manners. While not necessary for Vite, we recommend that libraries state that all CSS files have side-effects so that your library will be [compatible with webpack](https://webpack.js.org/guides/tree-shaking/#mark-the-file-as-side-effect-free).

```json
/// file: package.json
{
"sideEffects": ["**/*.css"]
}
```

Make sure that `"sideEffects"` is correctly set. If a file with side effects is incorrectly marked as having no side effects, it can result in broken functionality. If your package has files with side effects, you can specify them in an array:

```json
/// file: package.json
{
"sideEffects": ["**/*.css", "./src/sideEffectfulFile.js"]
}
```

This will treat only the specified files as having side effects.

## TypeScript

You should ship type definitions for your library even if you don't use TypeScript yourself so that people who do get proper intellisense when using your library. `@sveltejs/package` makes the process of generating types mostly opaque to you. By default, when packaging your library, type definitions are auto-generated for JavaScript, TypeScript and Svelte files. All you need to ensure is that the `types` condition in the [exports](#anatomy-of-a-package-json-exports) map points to the correct files. When initialising a library project through `npm create svelte@latest`, this is automatically setup for the root export.
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp