Skip to content

Commit

Permalink
feat!: remove commonjs build (#522)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
dominikg committed Dec 7, 2022
1 parent 0c777cc commit 956e381
Show file tree
Hide file tree
Showing 33 changed files with 163 additions and 129 deletions.
5 changes: 5 additions & 0 deletions .changeset/slow-paws-grow.md
@@ -0,0 +1,5 @@
---
'@sveltejs/vite-plugin-svelte': major
---

remove cjs build
2 changes: 1 addition & 1 deletion .eslintrc.js
Expand Up @@ -27,7 +27,7 @@ module.exports = {
'node/no-missing-import': [
'error',
{
allowModules: ['types', 'estree', 'testUtils'],
allowModules: ['types', 'estree', 'testUtils', '@sveltejs/vite-plugin-svelte'],
tryExtensions: ['.ts', '.js', '.jsx', '.tsx']
}
],
Expand Down
31 changes: 31 additions & 0 deletions docs/faq.md
Expand Up @@ -177,3 +177,34 @@ There is no golden rule, but you can follow these recommendations:

This warning only occurs if you use non-default settings in your vite config that can cause problems in combination with prebundleSvelteLibraries.
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.

### how can I use vite-plugin-svelte from commonjs

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.

In case you have to, use dynamic import to load vite-plugin-svelte's esm code from cjs like this:

```diff
// vite.config.cjs
const { defineConfig } = require('vite');
- const { svelte } = require('@sveltejs/vite-plugin-svelte');
module.exports = defineConfig(async ({ command, mode }) => {
+ const { svelte } = await import('@sveltejs/vite-plugin-svelte');
return {plugins:[svelte()]}
}
```

And for `vitePreprocess` you have to set up a lazy promise as top-level-await doesn't work for esm imports in cjs:

```diff
- const {vitePreprocess} = require('@sveltejs/vite-plugin-svelte')
+ const vitePreprocess = import('@sveltejs/vite-plugin-svelte').then(m => m.vitePreprocess())

module.exports = {
- preprocess: vitePreprocess()
+ preprocess: {
+ script:async (options) => (await vitePreprocess).script(options),
+ style:async (options) => (await vitePreprocess).style(options),
+ }
}
```
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -46,7 +46,7 @@
"rimraf": "^3.0.2",
"svelte": "^3.53.1",
"typescript": "^4.9.3",
"vite": "^4.0.0-beta.0",
"vite": "^4.0.0-beta.1",
"vitest": "^0.25.4"
},
"lint-staged": {
Expand All @@ -65,13 +65,13 @@
"pnpm": {
"overrides": {
"@sveltejs/vite-plugin-svelte": "workspace:*",
"vite": "^4.0.0-beta.0"
"vite": "^4.0.0-beta.1"
},
"peerDependencyRules": {
"allowedVersions": {
"stylus": "^0.58.0",
"postcss-load-config": "^4.0.0",
"vite": "^4.0.0-beta.0"
"vite": "^4.0.0-beta.1"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-tests/autoprefixer-browerslist/package.json
Expand Up @@ -17,7 +17,7 @@
"postcss-load-config": "^4.0.1",
"svelte": "^3.53.1",
"svelte-preprocess": "^4.10.7",
"vite": "^4.0.0-beta.0"
"vite": "^4.0.0-beta.1"
},
"type": "module"
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/configfile-custom/package.json
Expand Up @@ -13,7 +13,7 @@
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "workspace:*",
"svelte": "^3.53.1",
"vite": "^4.0.0-beta.0"
"vite": "^4.0.0-beta.1"
},
"type": "module"
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/configfile-esm/package.json
Expand Up @@ -14,7 +14,7 @@
"@sveltejs/vite-plugin-svelte": "workspace:*",
"svelte": "^3.53.1",
"svelte-preprocess": "^4.10.7",
"vite": "^4.0.0-beta.0"
"vite": "^4.0.0-beta.1"
},
"type": "module"
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/css-none/package.json
Expand Up @@ -11,6 +11,6 @@
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "workspace:*",
"svelte": "^3.53.1",
"vite": "^4.0.0-beta.0"
"vite": "^4.0.0-beta.1"
}
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/custom-extensions/package.json
Expand Up @@ -10,7 +10,7 @@
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "workspace:*",
"svelte": "^3.53.1",
"vite": "^4.0.0-beta.0"
"vite": "^4.0.0-beta.1"
},
"type": "module"
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/env/package.json
Expand Up @@ -10,7 +10,7 @@
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "workspace:*",
"svelte": "^3.53.1",
"vite": "^4.0.0-beta.0"
"vite": "^4.0.0-beta.1"
},
"type": "module"
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/hmr/package.json
Expand Up @@ -15,7 +15,7 @@
"e2e-test-dep-vite-plugins": "file:../_test_dependencies/vite-plugins",
"node-fetch": "^3.3.0",
"svelte": "^3.53.1",
"vite": "^4.0.0-beta.0"
"vite": "^4.0.0-beta.1"
},
"type": "module"
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/import-queries/package.json
Expand Up @@ -12,6 +12,6 @@
"@sveltejs/vite-plugin-svelte": "workspace:*",
"sass": "^1.56.1",
"svelte": "^3.53.1",
"vite": "^4.0.0-beta.0"
"vite": "^4.0.0-beta.1"
}
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/inspector-kit/package.json
Expand Up @@ -11,7 +11,7 @@
"devDependencies": {
"@sveltejs/kit": "^1.0.0-next.572",
"svelte": "^3.53.1",
"vite": "^4.0.0-beta.0"
"vite": "^4.0.0-beta.1"
},
"type": "module"
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/inspector-vite/package.json
Expand Up @@ -11,6 +11,6 @@
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "workspace:*",
"svelte": "^3.53.1",
"vite": "^4.0.0-beta.0"
"vite": "^4.0.0-beta.1"
}
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/kit-node/package.json
Expand Up @@ -20,7 +20,7 @@
"svelte-i18n": "^3.6.0",
"tiny-glob": "^0.2.9",
"typescript": "^4.9.3",
"vite": "^4.0.0-beta.0"
"vite": "^4.0.0-beta.1"
},
"type": "module"
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/package-json-svelte-field/package.json
Expand Up @@ -14,7 +14,7 @@
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "workspace:*",
"svelte": "^3.53.1",
"vite": "^4.0.0-beta.0"
"vite": "^4.0.0-beta.1"
},
"type": "module"
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/prebundle-svelte-deps/package.json
Expand Up @@ -20,6 +20,6 @@
"sass": "^1.56.1",
"svelte": "^3.53.1",
"svelte-preprocess": "^4.10.7",
"vite": "^4.0.0-beta.0"
"vite": "^4.0.0-beta.1"
}
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/preprocess-with-vite/package.json
Expand Up @@ -12,7 +12,7 @@
"sass": "^1.56.1",
"stylus": "^0.59.0",
"svelte": "^3.53.1",
"vite": "^4.0.0-beta.0"
"vite": "^4.0.0-beta.1"
},
"type": "module"
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/resolve-exports-svelte/package.json
Expand Up @@ -14,6 +14,6 @@
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "workspace:*",
"svelte": "3.53.1",
"vite": "^4.0.0-beta.0"
"vite": "^4.0.0-beta.1"
}
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/svelte-preprocess/package.json
Expand Up @@ -13,7 +13,7 @@
"svelte": "^3.53.1",
"svelte-preprocess": "^4.10.7",
"typescript": "^4.9.3",
"vite": "^4.0.0-beta.0"
"vite": "^4.0.0-beta.1"
},
"type": "module"
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/ts-type-import/package.json
Expand Up @@ -13,7 +13,7 @@
"@types/node": "^18.11.11",
"svelte": "^3.53.1",
"svelte-preprocess": "^4.10.7",
"vite": "^4.0.0-beta.0"
"vite": "^4.0.0-beta.1"
},
"type": "module"
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/vite-ssr-esm/package.json
Expand Up @@ -21,6 +21,6 @@
"npm-run-all": "^4.1.5",
"serve-static": "^1.15.0",
"svelte": "^3.53.1",
"vite": "^4.0.0-beta.0"
"vite": "^4.0.0-beta.1"
}
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/vite-ssr/package.json
Expand Up @@ -18,6 +18,6 @@
"express": "^4.18.2",
"serve-static": "^1.15.0",
"svelte": "^3.53.1",
"vite": "^4.0.0-beta.0"
"vite": "^4.0.0-beta.1"
}
}
5 changes: 3 additions & 2 deletions packages/e2e-tests/vite-ssr/vite.config.js
@@ -1,7 +1,8 @@
const { defineConfig } = require('vite');
const { svelte } = require('@sveltejs/vite-plugin-svelte');

module.exports = defineConfig(({ command, mode }) => {
module.exports = defineConfig(async ({ command, mode }) => {
//eslint-disable-next-line node/no-missing-import
const { svelte } = await import('@sveltejs/vite-plugin-svelte');
return {
plugins: [
svelte({
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/big-component-library-kit/package.json
Expand Up @@ -20,7 +20,7 @@
"svelte-check": "^2.10.1",
"svelte-preprocess": "^4.10.7",
"typescript": "^4.9.3",
"vite": "^4.0.0-beta.0"
"vite": "^4.0.0-beta.1"
},
"type": "module"
}
Expand Up @@ -24,6 +24,6 @@
"lodash-es": "^4.17.21",
"svelte": "^3.53.1",
"svelte-preprocess": "^4.10.7",
"vite": "^4.0.0-beta.0"
"vite": "^4.0.0-beta.1"
}
}
2 changes: 1 addition & 1 deletion packages/playground/big-component-library/package.json
Expand Up @@ -15,7 +15,7 @@
"carbon-preprocess-svelte": "^0.9.1",
"svelte": "^3.53.1",
"svelte-preprocess": "^4.10.7",
"vite": "^4.0.0-beta.0"
"vite": "^4.0.0-beta.1"
},
"dependencies": {
"lodash-es": "^4.17.21"
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/big/package.json
Expand Up @@ -10,6 +10,6 @@
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "workspace:*",
"svelte": "^3.53.1",
"vite": "^4.0.0-beta.0"
"vite": "^4.0.0-beta.1"
}
}
2 changes: 1 addition & 1 deletion packages/playground/kit-demo-app/package.json
Expand Up @@ -18,7 +18,7 @@
"svelte": "^3.53.1",
"svelte-check": "^2.10.1",
"typescript": "^4.9.3",
"vite": "^4.0.0-beta.0"
"vite": "^4.0.0-beta.1"
},
"type": "module"
}
2 changes: 1 addition & 1 deletion packages/playground/optimizedeps-include/package.json
Expand Up @@ -12,6 +12,6 @@
"@sveltejs/vite-plugin-svelte": "workspace:*",
"svelte": "^3.53.1",
"tinro": "^0.6.12",
"vite": "^4.0.0-beta.0"
"vite": "^4.0.0-beta.1"
}
}
2 changes: 1 addition & 1 deletion packages/playground/windicss/package.json
Expand Up @@ -14,7 +14,7 @@
"@sveltejs/vite-plugin-svelte": "workspace:*",
"diff-match-patch": "^1.0.5",
"svelte": "^3.53.1",
"vite": "^4.0.0-beta.0",
"vite": "^4.0.0-beta.1",
"vite-plugin-windicss": "^1.8.8"
}
}
11 changes: 4 additions & 7 deletions packages/vite-plugin-svelte/package.json
Expand Up @@ -9,21 +9,18 @@
"*.d.ts"
],
"type": "module",
"main": "dist/index.cjs",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"require": "./dist/index.cjs"
"import": "./dist/index.js"
},
"./package.json": "./package.json",
"./src/ui/*": "./src/ui/*"
},
"scripts": {
"dev": "pnpm build:ci --sourcemap --watch src",
"build:ci": "rimraf dist && tsup-node src/index.ts src/preprocess.ts --format esm,cjs --no-splitting --shims",
"build:ci": "rimraf dist && tsup-node src/index.ts --format esm",
"build": "pnpm build:ci --dts --sourcemap"
},
"engines": {
Expand Down Expand Up @@ -54,14 +51,14 @@
},
"peerDependencies": {
"svelte": "^3.44.0",
"vite": "^4.0.0-beta.0"
"vite": "^4.0.0-beta.1"
},
"devDependencies": {
"@types/debug": "^4.1.7",
"esbuild": "^0.15.18",
"rollup": "^2.79.1",
"svelte": "^3.53.1",
"tsup": "^6.5.0",
"vite": "^4.0.0-beta.0"
"vite": "^4.0.0-beta.1"
}
}

0 comments on commit 956e381

Please sign in to comment.