You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+15-7Lines changed: 15 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -75,7 +75,11 @@ export default {
75
75
}
76
76
}),
77
77
// see NOTICE below
78
-
resolve({ browser:true }),
78
+
resolve({
79
+
browser:true,
80
+
exportConditions: ['svelte'],
81
+
extensions: ['.svelte']
82
+
}),
79
83
// ...
80
84
]
81
85
}
@@ -89,22 +93,26 @@ export default {
89
93
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.
90
94
91
95
92
-
## `pkg.svelte`
96
+
## `svelte` exports condition
93
97
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...
95
99
96
100
```js
97
101
{
98
102
"name":"some-component",
99
103
100
104
// 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
+
}
102
110
}
103
111
```
104
112
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.
106
114
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`.
108
116
109
117
If you are publishing a package containing multiple components, you can create an `index.js` file that re-exports all the components, like this:
110
118
@@ -113,7 +121,7 @@ export { default as Component1 } from './Component1.svelte';
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.
0 commit comments