Skip to content

Commit 607e0a9

Browse files
authored
[docs] recommend svelte export condition rather than svelte mainField (#204)
1 parent 2f46031 commit 607e0a9

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

README.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ export default {
7575
}
7676
}),
7777
// see NOTICE below
78-
resolve({ browser: true }),
78+
resolve({
79+
browser: true,
80+
exportConditions: ['svelte'],
81+
extensions: ['.svelte']
82+
}),
7983
// ...
8084
]
8185
}
@@ -89,22 +93,26 @@ export default {
8993
If you are using the `preprocess` feature, then your callback responses may — in addition to the `code` and `map` values described in the Svelte compile docs — also optionally include a `dependencies` array. This should be the paths of additional files that the preprocessor result in some way depends upon. In Rollup 0.61+ in watch mode, any changes to these additional files will also trigger re-builds.
9094

9195

92-
## `pkg.svelte`
96+
## `svelte` exports condition
9397

94-
If you're importing a component from your node_modules folder, and that component's package.json has a `"svelte"` property...
98+
If you're importing a component from your node_modules folder, and that component's `package.json` has a `"svelte"` property in its `exports` condition...
9599

96100
```js
97101
{
98102
"name": "some-component",
99103

100104
// this means 'some-component' resolves to 'some-component/src/SomeComponent.svelte'
101-
"svelte": "src/MyComponent.svelte"
105+
"exports": {
106+
".": {
107+
"svelte": "./src/MyComponent.svelte"
108+
}
109+
}
102110
}
103111
```
104112

105-
...then this plugin will ensure that your app imports the *uncompiled* component source code. That will result in a smaller, faster app (because code is deduplicated, and shared functions get optimized quicker), and makes it less likely that you'll run into bugs caused by your app using a different version of Svelte to the component.
113+
...then this plugin together with `@rollup/plugin-node-resolve` will ensure that your app imports the *uncompiled* component source code. That will result in a smaller, faster app (because code is deduplicated, and shared functions get optimized quicker), and makes it less likely that you'll run into bugs caused by your app using a different version of Svelte to the component.
106114

107-
Conversely, if you're *publishing* a component to npm, you should ship the uncompiled source (together with the compiled distributable, for people who aren't using Svelte elsewhere in their app) and include the `"svelte"` property in your package.json.
115+
Conversely, if you're *publishing* a component to npm, you should ship the uncompiled source (together with the compiled distributable, for people who aren't using Svelte elsewhere in their app) and include the `"svelte"` property in the `exports` of your `package.json`.
108116

109117
If you are publishing a package containing multiple components, you can create an `index.js` file that re-exports all the components, like this:
110118

@@ -113,7 +121,7 @@ export { default as Component1 } from './Component1.svelte';
113121
export { default as Component2 } from './Component2.svelte';
114122
```
115123

116-
and so on. Then, in `package.json`, set the `svelte` property to point to this `index.js` file.
124+
and so on. Then, in `package.json`, set the `svelte` condition to point to this `index.js` file. Or you may create an export for each individual Svelte file. Using a single `index.js` which exports all files will allow multiple components to be imported with a single line, but may load more slowly during development. An export per file may load more quickly during development but require a separate import statement for each file.
117125

118126

119127
## Extracting CSS

0 commit comments

Comments
 (0)