Setting up a new project with Svelte, Webpack, and TypeScript based on this template. Ran the scripts/setupTypeScript.js
script to switch to TypeScript after initial setup.
Encountering errors in VSCode and TypeScript when importing non-TypeScript files:
import myContent from './some-file.txt';
// -> Cannot find module './some-file.txt' or its corresponding type declarations.ts(2307)
The imports work technically, but constant errors are disrupting live-reload. Is there a way for TypeScript to ignore these imports and trust Webpack to handle them? Some of the files are binary, so copying into .ts
files isn't an option.
Below are the provided Webpack and TS configurations:
webpack.config.js:
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const path = require('path');
const sveltePreprocess = require('svelte-preprocess');
const mode = process.env.NODE_ENV || 'development';
const prod = mode === 'production';
module.exports = {
// webpack configuration here
};
tsconfig.json:
{
"extends": "@tsconfig/svelte/tsconfig.json",
"include": ["src/**/*.ts", "src/node_modules/**/*.ts"],
"exclude": ["node_modules/*", "__sapper__/*", "static/*"]
}