从Angular 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
];

你不应该将项目中的css文件直接注入到index.html中。Main.css是通过种子注入的,而bootstrap css应该通过project.config.ts添加。参见:https://github.com/mgechev/angular2-seed/wiki/Add-external-scripts-and-styles

不要像那样把直接链接放到你的CSS中。而是使用project。在index.html中注入CSS。在"tools/config"文件夹下查找此文件。

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

最新更新