2

Angular2-seedを使用してアプリケーションを開発しています。静的デモを作成しようとしていますが、いくつかのリソースが見つかりません。

npm run build.devは、プロジェクト ディレクトリに次のファイルを作成します。

project |-- dev |-- app |-- app files... |-- css |-- main.css |-- other css files... |-- index.html |-- tsconfig.json

index.html :

<!DOCTYPE html>
<html lang="en">
<head>

<base href="/">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Dashboard</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- inject:css -->
<link rel="stylesheet" href="/node_modules/bootstrap/dist/css/bootstrap.css?1474900046924">
<link rel="stylesheet" href="/dist/dev/css/main.css?1474900046926">
<!-- More css... -->
<!-- endinject -->

<sd-app>Loading...</sd-app>

<script>
// Fixes undefined module function in SystemJS bundle
function module() {}
</script>

<script src="/app/system-config.js"></script>

<!-- libs:js -->
<script src="/node_modules/zone.js/dist/zone.js?1474900046920"></script>
<!-- More libs... -->
<!-- endinject -->

<script>
System.import('app/main')
  .catch(function (e) {
    console.error(e,
      'Report this error at https://github.com/mgechev/angular2-seed/issues');
  });
</script>

次のエラー メッセージが表示されます。

Failed to load resource: net::ERR_FILE_NOT_FOUND file:///node_modules/bootstrap/dist/css/bootstrap.css?1474900046924
Failed to load resource: net::ERR_FILE_NOT_FOUND file:///dist/dev/css/main.css?1474900046926
Failed to load resource: net::ERR_FILE_NOT_FOUND file:///app/system-config.js
Uncaught ReferenceError: System is not defined

そのため、ブラウザはルート ディレクトリでリソースを見つけようとするため、リソースが見つかりません。

ただし、これを変更すると:

<link rel="stylesheet" href="/dist/dev/css/main.css?1474900046926">

これに:

<link rel="stylesheet" href="./css/main.css?1474900046926">

以下でのみ機能します。

<link rel="stylesheet" href="/<absolute-path>/dist/dev/css/main.css?1474900046926">

しかし、これは本当に厄介で、Systemまだ見つかっていません。

それを行う方法のアイデアはありますか?

アップデート

私はすでにproject.config.tsファイルを使用してcssアセットとjsライブラリを注入しています:

// Add `NPM` third-party libraries to be injected/bundled.
this.NPM_DEPENDENCIES = [
  ...this.NPM_DEPENDENCIES,
  { src: 'bootstrap/dist/css/bootstrap.css', inject: true},
  // More css and js files
];
4

2 に答える 2

0

そのような CSS への直接リンクを置かないでください。代わりに、project.config ファイルを使用して CSS を index.html に挿入します。「tools/config」フォルダの下でこのファイルを探します。

参照: https://github.com/mgechev/angular2-seed/wiki/Add-external-scripts-and-styles

于 2016-09-27T07:55:35.353 に答える
0

プロジェクトにある css ファイルを index.html に直接挿入しないでください。Main.css はシードによって注入され、ブートストラップ css は project.config.ts を介して追加する必要があります。参照: https://github.com/mgechev/angular2-seed/wiki/Add-external-scripts-and-styles

于 2016-09-27T07:59:53.473 に答える