0
# component.ts
import template from './template.html' 

结果是:

  TS2307: Cannot find module './template.html' or its corresponding type declarations.

ts-loader-default_e3b0c44298fc1c14

我试过把raw-loaderbefore 和 after ts-loader,它没有任何区别。

loaders.unshift({
  test: /\.html$/,
  exclude: /node_modules/,
  use: 'raw-loader',
});

我也尝试过:

# component.ts
import template from '!!raw-loader!./template.html' 

这也不起作用。

跟踪分辨率显示:

======== Resolving module './heading.html' from 'app/javascript/components/heading/heading.component.ts'. ========
Loading module as file / folder, candidate module location 'app/javascript/components/heading/heading.html', target file type 'TypeScript'.
File 'app/javascript/components/heading/heading.html.ts' does not exist.
File 'app/javascript/components/heading/heading.html.tsx' does not exist.
File 'app/javascript/components/heading/heading.html.d.ts' does not exist.
Directory 'app/javascript/components/heading/heading.html' does not exist, skipping all lookups in it.
Loading module as file / folder, candidate module location 'app/javascript/components/heading/heading.html', target file type 'JavaScript'.
File 'app/javascript/components/heading/heading.html.js' does not exist.
File 'app/javascript/components/heading/heading.html.jsx' does not exist.
Directory 'app/javascript/components/heading/heading.html' does not exist, skipping all lookups in it.
======== Module name './heading.html' was not resolved. ========

为什么要尝试将其加载为打字稿或 javascript?我怎么能告诉它不要那样做?

4

0 回答 0