dividab / tsconfig-paths

Load node modules according to tsconfig paths, in run-time or via API.
MIT License
1.8k stars 100 forks source link

Exclude certain file extensions #159

Open Elias-Graf opened 3 years ago

Elias-Graf commented 3 years ago

I've read the readme several times now and I couldn't find a way to exclude certain file types. The specific problem I'm having is that I am importing style sheets, for example import style from "@/styles/ColorDisplay.module.scss"; I now want test the code with mocha, and the typescript compiler fails with: Cannot find module '@/styles/ColorDisplay.module.scss' or its corresponding type declarations.. I've googled and the top result seems to be a npm module called ignore-styles. With the little knowledge I have, I assume that because I'm using a path, tsconfig-pahts is resolving it before giving ignore-styles a chance (sorry if that's not the case, like I said, I'm not experienced.).

Here is what I'm trying to do in my .mocharc.js:

const tsNode = require("ts-node");
require('ignore-styles').default(['.sass', '.scss']);
const tsConfigPaths = require("tsconfig-paths");

tsNode.register({ project: "tsconfig.testing.json" });
tsConfigPaths.register();

module.exports = {
    extension: [".ts", ".tsx"],
    spec: ["specs/**/*.spec.tsx"],
};

I have also tried doing:

require.extensions[".scss"] = () => null;

So is it possible that tsconfig-paths is just snatching all the imports, before other plugins have a chance to ignore it?

(Again, sorry if I'm being stupid)