Я создаю приложение с помощью TypeScript и веб-пакета.В моих файлах .ts у меня есть такой код:
let template = require('./example.component.html');
let style = require('./example.component.scss');
Мои загрузчики Webpack выглядят так:
{
test: /\.scss$/,
exclude: [path.resolve(__dirname, 'demo/index.scss')],
use: ['to-string-loader', 'css-loader', 'postcss-loader', 'sass-loader']
},
{
test: /\.html$/,
exclude: /node_modules/,
use: ['html-loader'],
}
У меня также есть файл ./test/mocha.opts сследующее содержимое:
--require ts-node/register
--require ./test/css-modules-compiler.js
--recursive
--module commonjs
и затем я выполняю свой тест:
mocha src/**/*.spec.ts
Выполнение приложения с помощью веб-пакета работает нормально.
Когда я выполняю тест, он выполняетне знаю, как загрузить файл .html, и я получаю следующую ошибку:
/path/to/project/node_modules/typescript/lib/typescript.js:117452
throw new Error("Could not find file: '" + fileName + "'.");
^
Error: Could not find file: '/path/to/project/src/example/example.component.html'.
Как правильно загрузить файл содержимого .html и выполнить свои тесты?