Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Anuglar2-找不到模块时出错_Javascript_Css_Angular_Import_Webpack - Fatal编程技术网

Javascript Anuglar2-找不到模块时出错

Javascript Anuglar2-找不到模块时出错,javascript,css,angular,import,webpack,Javascript,Css,Angular,Import,Webpack,我正在使用Angular2 rc4,目前我可以使用ExtractTextPlugin导入css文件。我使用html加载程序没有任何问题。然而,当我尝试加载css文件时,我得到了错误:找不到模块“/app.component.css”或期望“样式”是字符串数组。我该如何解决这个问题? app.comont.ts import {Component} from '@angular/core'; import {ROUTER_DIRECTIVES} from '@angular/router'; c

我正在使用Angular2 rc4,目前我可以使用ExtractTextPlugin导入css文件。我使用html加载程序没有任何问题。然而,当我尝试加载css文件时,我得到了错误:找不到模块“/app.component.css”期望“样式”是字符串数组。我该如何解决这个问题? app.comont.ts

import {Component} from '@angular/core';
import {ROUTER_DIRECTIVES} from '@angular/router';

const template = require('./app.component.html'); 
const sytles = require('./app.component.css'); 

// Components
import {NavComponent} from './nav/nav.component';
import {FooterComponent} from './footer/footer.component';

@Component({
    selector: 'my-app',
    template: template,
    directives: [ROUTER_DIRECTIVES, NavComponent, FooterComponent],
    styles: [sytles],
    precompile: [NavComponent, FooterComponent]
})

export class AppComponent {
}
webpack.config.js

var webpack = require("webpack");
var ExtractTextPlugin = require('extract-text-webpack-plugin');


module.exports = {
  entry: {
    "vendor": "./src/vendor",
    "app": "./src/boot"
  },
  output: {
    path: __dirname,
    filename: "./dist/[name].bundle.js"
  },
  resolve: {
    extensions: ['', '.ts', '.js']
  },
  devtool: 'source-map',
  module: {
    loaders: [
      {
        test: /\.ts/,
        loaders: ['ts-loader'],
        exclude: /node_modules/
      },
      {
          test: /\.html$/,
          loader: 'html'
      },
      {
          test: /\.css$/,
          loader: ExtractTextPlugin.extract("style-loader", "css-loader")

      }
    ]
  },
  plugins: [
    new webpack.optimize.CommonsChunkPlugin(/* chunkName= */"vendor", /* filename= */"./dist/vendor.bundle.js"),
new ExtractTextPlugin('[name].css')

  ]
}

应该是

styles:[styles];,

应该是

styles:[styles];,

使用import而不是require,它将为您和您需要的模板创建一个单独的app.css文件
angular2模板加载器
,然后您不需要使用require on模板,它将为您编译

注意:-当您在css上导入时,您不需要将其添加到组件样式中,您可以直接在html中使用它。例如,当您使用引导时,您不想将其添加到每个组件中的每个样式中,但只想加载一次,那么您只需在app.ts中导入“引导”,即可在任何地方使用它

webppack
{test:/\.ts$/,加载程序:[“ts加载程序”,“angular2模板加载程序”]}

组成部分
使用import而不是require,它将为您和您需要的模板创建一个单独的app.css文件
angular2模板加载器
,然后您不需要使用require on模板,它将为您编译

注意:-当您在css上导入时,您不需要将其添加到组件样式中,您可以直接在html中使用它。例如,当您使用引导时,您不想将其添加到每个组件中的每个样式中,但只想加载一次,那么您只需在app.ts中导入“引导”,即可在任何地方使用它

webppack
{test:/\.ts$/,加载程序:[“ts加载程序”,“angular2模板加载程序”]}

组成部分

我仍然得到错误:找不到模块“/app.component.css”你的文件夹结构是什么样的我不确定,但也许你需要把ExtractTextPlugin放在网页插件配置中,如文档中所述?@FriOne,是的,我在发布这篇文章后试过了。没有lucktemplateUrl:'quest summary.component.html',styleURL:['quest-summary.component.css']我仍然得到错误:找不到模块“/app.component.css”你的文件夹结构是什么样子我不确定,但也许你需要像文档中描述的那样将ExtractTextPlugin放入webpack插件配置中?@FriOne,是的,我在发布这篇文章后试过了。没有lucktemplateUrl:'quest summary.component.html',StyleURL:['quest-summary.component.css']也可能需要是StyleURL:[styles],但根据您导入它的方式,我对此不肯定。没有,这两个想法都不肯定。也可能需要是StyleURL:[styles],但根据您导入它的方式,我对此不肯定。没有,这两个想法都适用。样式:[“path”]//不要使用require是的,我知道URL。我正在尝试做加载程序。我只在css文件上使用导入,而且效果很好。还有样式URL:['./app.component.css]样式:[“path”]//不要使用require是的,我知道URL。我正在尝试做加载程序。我只在css文件上使用导入,而且效果很好。还有样式URL:['./app.component.css]
templateUrl :"path"