Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: "fix: dynamicImport svelte config #47" #49

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/vite-plugin-svelte/api-extractor.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"projectFolder": ".",

"mainEntryPointFilePath": "./temp/index.d.ts",
"mainEntryPointFilePath": "./dist/index.d.ts",

"dtsRollup": {
"enabled": true,
Expand Down
10 changes: 6 additions & 4 deletions packages/vite-plugin-svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
"dist"
],
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"scripts": {
"dev": "tsc -p . -w --incremental",
"build": "rimraf dist && run-s build-bundle build-types",
"build-bundle": "node scripts/build-bundle.js",
"build-types": "tsc -p . --emitDeclarationOnly --outDir temp && api-extractor run && rimraf temp"
"build": "rimraf dist && tsup src/index.ts --dts --format cjs,esm --no-splitting && api-extractor run && rimraf temp"
},
"engines": {
"node": ">=12.0.0"
Expand Down Expand Up @@ -50,12 +49,15 @@
"@types/es-module-lexer": "^0.3.0",
"@types/estree": "^0.0.47",
"@types/hash-sum": "^1.0.0",
"@types/node": "^15.6.1",
"@windicss/plugin-utils": "^0.15.7",
"esbuild": "~0.9.7",
"locate-character": "^2.0.5",
"magic-string": "^0.25.7",
"rollup": "^2.45.2",
"svelte": "^3.37.0",
"typescript": "^4.3.2",
"vite": "^2.2.3"
}
},
"type": "module"
}
32 changes: 0 additions & 32 deletions packages/vite-plugin-svelte/scripts/build-bundle.js

This file was deleted.

15 changes: 6 additions & 9 deletions packages/vite-plugin-svelte/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as path from 'path';
import path from 'path';
import { readFileSync } from 'fs';
import { HmrContext, IndexHtmlTransformContext, ModuleNode, Plugin, UserConfig } from 'vite';

// @ts-ignore
import * as relative from 'require-relative';
import relative from 'require-relative';

import { handleHotUpdate } from './handleHotUpdate';
import { log } from './utils/log';
Expand Down Expand Up @@ -165,7 +166,7 @@ export default function vitePluginSvelte(inlineOptions?: Partial<Options>): Plug
const file = `${name}/package.json`;
const resolved = relative.resolve(file, path.dirname(importer));
dir = path.dirname(resolved);
pkg = require(resolved);
pkg = JSON.parse(readFileSync(resolved, { encoding: 'utf8' }));
} catch (err) {
if (err.code === 'MODULE_NOT_FOUND') return null;
if (err.code === 'ERR_PACKAGE_PATH_NOT_EXPORTED') {
Expand Down Expand Up @@ -206,7 +207,7 @@ export default function vitePluginSvelte(inlineOptions?: Partial<Options>): Plug

cache.update(compileData);
if (compileData.dependencies?.length && options.server) {
compileData.dependencies.forEach((d) => this.addWatchFile(d));
compileData.dependencies.forEach(d => this.addWatchFile(d));
}
log.debug(`transform returns compiled js for ${filename}`);
return compileData.compiled.js;
Expand Down Expand Up @@ -237,13 +238,9 @@ export default function vitePluginSvelte(inlineOptions?: Partial<Options>): Plug
if (pkg_export_errors.size > 0) {
log.warn(
`The following packages did not export their \`package.json\` file so we could not check the "svelte" field. If you had difficulties importing svelte components from a package, then please contact the author and ask them to export the package.json file.`,
Array.from(pkg_export_errors, (s) => `- ${s}`).join('\n')
Array.from(pkg_export_errors, s => `- ${s}`).join('\n')
);
}
}
};
}

// overwrite for cjs require('...')() usage
module.exports = vitePluginSvelte;
vitePluginSvelte['default'] = vitePluginSvelte;