【发布时间】:2019-02-01 05:38:06
【问题描述】:
我正在使用 TypeScript 和 webpack 构建一个应用程序。 在我的 .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
使用 webpack 执行应用程序工作正常。
当我执行测试时,它不知道如何加载 .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 内容文件并执行我的测试?
【问题讨论】:
标签: typescript mocha.js