如何让组件中的Angular 4 @import样式工作?

时间:2017-05-17 06:34:30

标签: angular npm sass

对于我的Angular 4.0.2通用应用程序,我有一个组件(BlogComponent):

@Component({
    templateUrl: 'blog.component.html',
    styleUrls: ['blog.component.scss']
})

在样式表中,我有:

@import '../../styles';

文件结构:

/src
    styles.scss
    /app
        /blog
            blog.component.scss

即。 app / blog中的根和组件样式表中的主样式表

当我运行npm start时,我得到:

Error: Compilation failed. Resource file not found: C:/Users/robba/Angular4/robbailey3/src/styles
    at ModuleResolutionHostAdapter.readResource (C:\Users\robba\Angular4\robbailey3\node_modules\@angular\compiler-cli\src\compiler_host.js:370:19)
    at CompilerHost.loadResource (C:\Users\robba\Angular4\robbailey3\node_modules\@angular\compiler-cli\src\compiler_host.js:243:85)
    at Object.get (C:\Users\robba\Angular4\robbailey3\node_modules\@angular\compiler\bundles\compiler.umd.js:24640:107)
    at DirectiveNormalizer._fetch (C:\Users\robba\Angular4\robbailey3\node_modules\@angular\compiler\bundles\compiler.umd.js:13297:45)
    at C:\Users\robba\Angular4\robbailey3\node_modules\@angular\compiler\bundles\compiler.umd.js:13426:53
    at Array.map (native)
    at DirectiveNormalizer._loadMissingExternalStylesheets (C:\Users\robba\Angular4\robbailey3\node_modules\@angular\compiler\bundles\compiler.umd.js:13426:14)
    at C:\Users\robba\Angular4\robbailey3\node_modules\@angular\compiler\bundles\compiler.umd.js:13429:26
    at process._tickCallback (internal/process/next_tick.js:109:7)
    at Module.runMain (module.js:607:11)
Compilation failed

但是,当我使用ng serve时,import语句可以正常工作。

如何让@import语句适用于npm startnpm build

0 个答案:

没有答案