Skip to content

Commit 956e381

Browse files
authored
feat!: remove commonjs build (#522)
* breaking: remove commonjs build * fix: tell eslint to shove it for missing import of v-p-s * fix: remove module and use import condition * fix: bump vite to 4.0.0-beta.1 to consume fix for cjs config bundling
1 parent 0c777cc commit 956e381

File tree

33 files changed

+163
-129
lines changed

33 files changed

+163
-129
lines changed

.changeset/slow-paws-grow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/vite-plugin-svelte': major
3+
---
4+
5+
remove cjs build

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = {
2727
'node/no-missing-import': [
2828
'error',
2929
{
30-
allowModules: ['types', 'estree', 'testUtils'],
30+
allowModules: ['types', 'estree', 'testUtils', '@sveltejs/vite-plugin-svelte'],
3131
tryExtensions: ['.ts', '.js', '.jsx', '.tsx']
3232
}
3333
],

docs/faq.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,34 @@ There is no golden rule, but you can follow these recommendations:
177177

178178
This warning only occurs if you use non-default settings in your vite config that can cause problems in combination with prebundleSvelteLibraries.
179179
You should not use prebundleSvelteLibraries during build or for ssr, disable one of the incompatible options to make that warning (and subsequent errors) go away.
180+
181+
### how can I use vite-plugin-svelte from commonjs
182+
183+
You really shouldn't. Svelte and Vite are esm first and the ecosystem is moving away from commonjs and so should you. Consider migrating to esm.
184+
185+
In case you have to, use dynamic import to load vite-plugin-svelte's esm code from cjs like this:
186+
187+
```diff
188+
// vite.config.cjs
189+
const { defineConfig } = require('vite');
190+
- const { svelte } = require('@sveltejs/vite-plugin-svelte');
191+
module.exports = defineConfig(async ({ command, mode }) => {
192+
+ const { svelte } = await import('@sveltejs/vite-plugin-svelte');
193+
return {plugins:[svelte()]}
194+
}
195+
```
196+
197+
And for `vitePreprocess` you have to set up a lazy promise as top-level-await doesn't work for esm imports in cjs:
198+
199+
```diff
200+
- const {vitePreprocess} = require('@sveltejs/vite-plugin-svelte')
201+
+ const vitePreprocess = import('@sveltejs/vite-plugin-svelte').then(m => m.vitePreprocess())
202+
203+
module.exports = {
204+
- preprocess: vitePreprocess()
205+
+ preprocess: {
206+
+ script:async (options) => (await vitePreprocess).script(options),
207+
+ style:async (options) => (await vitePreprocess).style(options),
208+
+ }
209+
}
210+
```

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"rimraf": "^3.0.2",
4747
"svelte": "^3.53.1",
4848
"typescript": "^4.9.3",
49-
"vite": "^4.0.0-beta.0",
49+
"vite": "^4.0.0-beta.1",
5050
"vitest": "^0.25.4"
5151
},
5252
"lint-staged": {
@@ -65,13 +65,13 @@
6565
"pnpm": {
6666
"overrides": {
6767
"@sveltejs/vite-plugin-svelte": "workspace:*",
68-
"vite": "^4.0.0-beta.0"
68+
"vite": "^4.0.0-beta.1"
6969
},
7070
"peerDependencyRules": {
7171
"allowedVersions": {
7272
"stylus": "^0.58.0",
7373
"postcss-load-config": "^4.0.0",
74-
"vite": "^4.0.0-beta.0"
74+
"vite": "^4.0.0-beta.1"
7575
}
7676
}
7777
}

packages/e2e-tests/autoprefixer-browerslist/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"postcss-load-config": "^4.0.1",
1818
"svelte": "^3.53.1",
1919
"svelte-preprocess": "^4.10.7",
20-
"vite": "^4.0.0-beta.0"
20+
"vite": "^4.0.0-beta.1"
2121
},
2222
"type": "module"
2323
}

packages/e2e-tests/configfile-custom/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"devDependencies": {
1414
"@sveltejs/vite-plugin-svelte": "workspace:*",
1515
"svelte": "^3.53.1",
16-
"vite": "^4.0.0-beta.0"
16+
"vite": "^4.0.0-beta.1"
1717
},
1818
"type": "module"
1919
}

packages/e2e-tests/configfile-esm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"@sveltejs/vite-plugin-svelte": "workspace:*",
1515
"svelte": "^3.53.1",
1616
"svelte-preprocess": "^4.10.7",
17-
"vite": "^4.0.0-beta.0"
17+
"vite": "^4.0.0-beta.1"
1818
},
1919
"type": "module"
2020
}

packages/e2e-tests/css-none/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
"devDependencies": {
1212
"@sveltejs/vite-plugin-svelte": "workspace:*",
1313
"svelte": "^3.53.1",
14-
"vite": "^4.0.0-beta.0"
14+
"vite": "^4.0.0-beta.1"
1515
}
1616
}

packages/e2e-tests/custom-extensions/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"devDependencies": {
1111
"@sveltejs/vite-plugin-svelte": "workspace:*",
1212
"svelte": "^3.53.1",
13-
"vite": "^4.0.0-beta.0"
13+
"vite": "^4.0.0-beta.1"
1414
},
1515
"type": "module"
1616
}

packages/e2e-tests/env/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"devDependencies": {
1111
"@sveltejs/vite-plugin-svelte": "workspace:*",
1212
"svelte": "^3.53.1",
13-
"vite": "^4.0.0-beta.0"
13+
"vite": "^4.0.0-beta.1"
1414
},
1515
"type": "module"
1616
}

0 commit comments

Comments
 (0)