Skip to content

Commit 4018ce6

Browse files
authored
Feat: async load config esm (#35)
* feat(vite-plugin-svelte): support esm in svelte.config.js (see #29) * update vite to 2.2.1 and update other dependencies * chore: update dependencies * test: improve stability * feat: add configFile option; use require to load cjs config * also try to load svelte.config.mjs * chore: update dependencies * improve changesets
1 parent 976f0c8 commit 4018ce6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+972
-617
lines changed

.changeset/blue-schools-bake.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': minor
3+
---
4+
5+
Feature: Support esm in svelte.config.js and svelte.config.mjs

.changeset/little-plums-grab.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': minor
3+
---
4+
5+
Feature: add configFile option

.ncurc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
22
packageFile: ['package.json', 'packages/**/package.json'],
3-
reject: ['husky']
3+
reject: ['husky', 'esbuild', 'slash']
44
};

package.json

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,27 @@
2727
"release": "pnpm run build && pnpx --no changeset publish"
2828
},
2929
"devDependencies": {
30-
"@changesets/changelog-github": "^0.3.0",
31-
"@changesets/cli": "^2.15.0",
32-
"@microsoft/api-extractor": "^7.13.2",
33-
"@types/fs-extra": "^9.0.10",
30+
"@changesets/changelog-github": "^0.4.0",
31+
"@changesets/cli": "^2.16.0",
32+
"@microsoft/api-extractor": "^7.14.0",
33+
"@types/fs-extra": "^9.0.11",
3434
"@types/jest": "^26.0.22",
35-
"@types/node": "^14.14.37",
36-
"@types/semver": "^7.3.4",
37-
"@typescript-eslint/eslint-plugin": "^4.20.0",
38-
"@typescript-eslint/parser": "^4.20.0",
39-
"chalk": "^4.1.0",
35+
"@types/node": "^14.14.41",
36+
"@types/semver": "^7.3.5",
37+
"@typescript-eslint/eslint-plugin": "^4.22.0",
38+
"@typescript-eslint/parser": "^4.22.0",
39+
"chalk": "^4.1.1",
4040
"cross-env": "^7.0.3",
4141
"enquirer": "^2.3.6",
4242
"esbuild": "~0.9.7",
43-
"eslint": "^7.23.0",
44-
"eslint-config-prettier": "^8.1.0",
43+
"eslint": "^7.25.0",
44+
"eslint-config-prettier": "^8.3.0",
4545
"eslint-plugin-html": "^6.1.2",
46-
"eslint-plugin-jest": "^24.3.3",
47-
"eslint-plugin-markdown": "^2.0.0",
46+
"eslint-plugin-jest": "^24.3.6",
47+
"eslint-plugin-markdown": "^2.1.0",
4848
"eslint-plugin-node": "^11.1.0",
49-
"eslint-plugin-prettier": "^3.3.1",
50-
"eslint-plugin-svelte3": "^3.1.2",
49+
"eslint-plugin-prettier": "^3.4.0",
50+
"eslint-plugin-svelte3": "^3.2.0",
5151
"execa": "^5.0.0",
5252
"fs-extra": "^9.1.0",
5353
"husky": "^4.3.8",
@@ -57,23 +57,23 @@
5757
"lint-staged": "^10.5.4",
5858
"minimist": "^1.2.5",
5959
"node-fetch": "^2.6.1",
60-
"npm-check-updates": "^11.3.0",
60+
"npm-check-updates": "^11.5.1",
6161
"npm-run-all": "^4.1.5",
6262
"playwright-core": "^1.10.0",
63-
"pnpm": "^6.0.1",
63+
"pnpm": "^6.2.1",
6464
"prettier": "^2.2.1",
6565
"prettier-plugin-svelte": "^2.2.0",
6666
"rimraf": "^3.0.2",
6767
"semver": "^7.3.5",
6868
"sirv": "^1.0.11",
6969
"slash": "^3.0.0",
70-
"stylelint": "^13.12.0",
70+
"stylelint": "^13.13.0",
7171
"stylelint-config-prettier": "^8.0.2",
72-
"stylelint-config-recommended": "^4.0.0",
72+
"stylelint-config-recommended": "^5.0.0",
7373
"svelte": "^3.37.0",
74-
"ts-jest": "^26.5.4",
75-
"typescript": "^4.2.3",
76-
"vite": "^2.1.5"
74+
"ts-jest": "^26.5.5",
75+
"typescript": "^4.2.4",
76+
"vite": "^2.2.3"
7777
},
7878
"husky": {
7979
"hooks": {

packages/playground/autoprefixer-browerslist/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
"devDependencies": {
1313
"@sveltejs/vite-plugin-svelte": "workspace:*",
1414
"autoprefixer": "^10.2.5",
15-
"postcss": "^8.2.9",
15+
"postcss": "^8.2.12",
1616
"postcss-load-config": "^3.0.1",
1717
"svelte": "^3.37.0",
18-
"svelte-hmr": "^0.14.0",
19-
"svelte-preprocess": "^4.7.0",
20-
"vite": "^2.1.5"
18+
"svelte-hmr": "^0.14.2",
19+
"svelte-preprocess": "^4.7.2",
20+
"vite": "^2.2.3"
2121
}
2222
}

packages/playground/big/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"devDependencies": {
1313
"@sveltejs/vite-plugin-svelte": "workspace:*",
1414
"svelte": "^3.37.0",
15-
"svelte-hmr": "^0.14.0",
16-
"vite": "^2.1.5"
15+
"svelte-hmr": "^0.14.2",
16+
"vite": "^2.2.3"
1717
}
1818
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/node_modules/
2+
/public/build/
3+
4+
.DS_Store
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# default svelte app template
2+
3+
Created with `npx degit sveltejs/template`
4+
5+
adapted to vite by moving index.html to root and replacing rollup config with vite
6+
7+
use pnpm
8+
9+
`pnpm dev` starts dev server
10+
`pnpm build` builds for production
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
it('should load config and work', async () => {
2+
expect(await page.textContent('h1')).toMatch('Hello world!');
3+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width,initial-scale=1" />
6+
7+
<title>Svelte app</title>
8+
9+
<script type="module" src="/src/main.js"></script>
10+
</head>
11+
12+
<body></body>
13+
</html>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "playground-configfile-custom",
3+
"private": true,
4+
"version": "1.0.0",
5+
"scripts": {
6+
"build": "vite build",
7+
"dev": "vite"
8+
},
9+
"dependencies": {
10+
"playground-hmr-test-dependency": "workspace:*"
11+
},
12+
"devDependencies": {
13+
"@sveltejs/vite-plugin-svelte": "workspace:*",
14+
"svelte": "^3.37.0",
15+
"svelte-hmr": "^0.14.2",
16+
"svelte-preprocess": "^4.7.2",
17+
"vite": "^2.2.3"
18+
}
19+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<script>
2+
import Dependency from 'playground-hmr-test-dependency';
3+
</script>
4+
5+
<h1>Hello world!</h1>
6+
<Dependency />
7+
8+
<style>
9+
h1 {
10+
color: #ff3e00;
11+
}
12+
</style>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import App from './App.svelte';
2+
3+
const app = new App({
4+
target: document.body
5+
});
6+
7+
export default app;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const sveltePreprocess = require('svelte-preprocess');
2+
3+
module.exports = {
4+
preprocess: sveltePreprocess()
5+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
const sveltePreprocess = require('svelte-preprocess');
3+
4+
module.exports = {
5+
preprocess: sveltePreprocess()
6+
};
7+
*/
8+
export default {
9+
emitCss: true
10+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const svelte = require('@sveltejs/vite-plugin-svelte');
2+
const { defineConfig } = require('vite');
3+
4+
module.exports = defineConfig(({ command, mode }) => {
5+
const isProduction = mode === 'production';
6+
return {
7+
plugins: [svelte({ configFile: 'svelte.config.custom.cjs' })],
8+
build: {
9+
minify: isProduction
10+
}
11+
};
12+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/node_modules/
2+
/public/build/
3+
4+
.DS_Store
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# default svelte app template
2+
3+
Created with `npx degit sveltejs/template`
4+
5+
adapted to vite by moving index.html to root and replacing rollup config with vite
6+
7+
use pnpm
8+
9+
`pnpm dev` starts dev server
10+
`pnpm build` builds for production
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// unfortunately this test does not work as jest is not fully compatible with esm
2+
// wait for jest 27 and see https://github.com/facebook/jest/issues/9430
3+
it('should load config and work', async () => {
4+
expect(await page.textContent('h1')).toMatch('Hello world!');
5+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width,initial-scale=1" />
6+
7+
<title>Svelte app</title>
8+
9+
<script type="module" src="/src/main.js"></script>
10+
</head>
11+
12+
<body></body>
13+
</html>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "playground-configfile-esm",
3+
"private": true,
4+
"version": "1.0.0",
5+
"scripts": {
6+
"build": "vite build",
7+
"dev": "vite"
8+
},
9+
"dependencies": {
10+
"playground-hmr-test-dependency": "workspace:*"
11+
},
12+
"devDependencies": {
13+
"@sveltejs/vite-plugin-svelte": "workspace:*",
14+
"svelte": "^3.37.0",
15+
"svelte-hmr": "^0.14.2",
16+
"svelte-preprocess": "^4.7.2",
17+
"vite": "^2.2.3"
18+
},
19+
"type": "module"
20+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<script>
2+
import Dependency from 'playground-hmr-test-dependency';
3+
</script>
4+
5+
<h1>Hello world!</h1>
6+
<Dependency />
7+
8+
<style>
9+
h1 {
10+
color: #ff3e00;
11+
}
12+
</style>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import App from './App.svelte';
2+
3+
const app = new App({
4+
target: document.body
5+
});
6+
7+
export default app;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import sveltePreprocess from 'svelte-preprocess';
2+
3+
export default {
4+
preprocess: sveltePreprocess()
5+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import svelte from '@sveltejs/vite-plugin-svelte';
2+
import { defineConfig } from 'vite';
3+
4+
export default defineConfig(({ command, mode }) => {
5+
const isProduction = mode === 'production';
6+
return {
7+
plugins: [svelte()],
8+
build: {
9+
minify: isProduction
10+
}
11+
};
12+
});

packages/playground/default-svelte-template-ts/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
"@sveltejs/vite-plugin-svelte": "workspace:*",
1313
"@tsconfig/svelte": "^1.0.10",
1414
"svelte": "^3.37.0",
15-
"svelte-hmr": "^0.14.0",
16-
"vite": "^2.1.5",
17-
"svelte-check": "^1.3.0",
18-
"svelte-preprocess": "^4.7.0",
19-
"typescript": "^4.2.3",
20-
"tslib": "^2.1.0"
15+
"svelte-hmr": "^0.14.2",
16+
"vite": "^2.2.3",
17+
"svelte-check": "^1.5.1",
18+
"svelte-preprocess": "^4.7.2",
19+
"typescript": "^4.2.4",
20+
"tslib": "^2.2.0"
2121
}
2222
}

packages/playground/default-svelte-template/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"devDependencies": {
1010
"@sveltejs/vite-plugin-svelte": "workspace:*",
1111
"svelte": "^3.37.0",
12-
"svelte-hmr": "^0.14.0",
13-
"vite": "^2.1.5"
12+
"svelte-hmr": "^0.14.2",
13+
"vite": "^2.2.3"
1414
}
1515
}

packages/playground/hmr/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
"devDependencies": {
1313
"@sveltejs/vite-plugin-svelte": "workspace:*",
1414
"svelte": "^3.37.0",
15-
"svelte-hmr": "^0.14.0",
16-
"vite": "^2.1.5",
15+
"svelte-hmr": "^0.14.2",
16+
"vite": "^2.2.3",
1717
"node-fetch": "^2.6.1"
1818
}
1919
}

packages/playground/kit-node/__tests__/serve.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ exports.serve = async function serve(root, isProd) {
1717
try {
1818
const serverProcess = execa(
1919
'svelte-kit',
20-
[isProd ? 'start' : 'dev', '--port', isProd ? '3200' : '3201'],
20+
[isProd ? 'preview' : 'dev', '--port', isProd ? '3200' : '3201'],
2121
{
2222
preferLocal: true,
2323
cwd: root,

packages/playground/kit-node/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
"scripts": {
66
"dev": "svelte-kit dev",
77
"build": "svelte-kit build",
8-
"start": "svelte-kit start"
8+
"preview": "svelte-kit preview"
99
},
1010
"devDependencies": {
11-
"@sveltejs/adapter-node": "^1.0.0-next.12",
12-
"@sveltejs/kit": "^1.0.0-next.71",
13-
"svelte": "^3.29.0",
14-
"vite": "^2.1.0"
11+
"@sveltejs/adapter-node": "^1.0.0-next.16",
12+
"@sveltejs/kit": "^1.0.0-next.88",
13+
"svelte": "^3.37.0",
14+
"vite": "^2.2.3"
1515
},
1616
"type": "module",
1717
"engines": {

0 commit comments

Comments
 (0)