在角度模板视觉tudio中集成sass

我在visual studio(
https://marketplace.visualstudio.com/items?itemName=MadsKristensen.ASPNETCoreTemplatePack)中使用angular2模板安装我的项目.我希望集成SASS但它会抛出异常“调用节点模块失败并显示错误:由于错误导致预渲染失败:ReferenceError:窗口未定义”.

这是我的webpack.config.js文件:

var sharedConfig = {
    resolve: { extensions: [ '', '.js', '.ts' ] },
    output: {
        filename: '[name].js',
        publicPath: '/dist/' // Webpack dev middleware, if enabled, handles requests for this URL prefix
    },
    module: {
        loaders: [
            { test: /\.ts$/, include: /ClientApp/, loader: 'ts', query: { silent: true } },
            { test: /\.html$/, loader: 'raw' },
            { test: /\.css$/, loader: 'to-string!css' },
            { test: /\.(png|jpg|jpeg|gif|svg)$/, loader: 'url', query: { limit: 25000 } },
            { test: /\.scss$/, loaders: ["style-loader", "css-loader", "sass-loader"] }
        ]
    }
};

和home.component.ts

@Component({
    selector: 'home',
    template: require('./home.component.html'),
    styles: [require('./home.component.scss')]
})

最佳答案 我几天前遇到过同样的问题.

我能够通过使用yoman生成器重新生成.net核心应用程序来解决这个问题.它与模板包具有相同的模板,但具有较新的包.

npm install -g yo generator-aspnetcore-spa
yo aspnetcore-spa

然后我安装了所有依赖项

npm install node-sass sass-loader raw-loader --save

编辑了webpack.config模块加载器

{ test: /\.scss$/, exclude: /node_modules/, loaders: ['raw-loader', 'sass-loader'] },

将scss文件添加到组件

@Component({
    selector: 'counter',
    templateUrl: './counter.component.html',
    styleUrls: ['./counter.component.scss']

})

创建了counter.component.scss

$font-stack:    Helvetica, sans-serif;
$primary-color: #ff0000;

p {
  font: 100% $font-stack;
  color: $primary-color;
}
点赞