sass - 将 sass 集成到 Angular 模板 Visual Studio 中

标签 sass webpack angular-template

我在 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 core 应用程序来解决此问题。它具有与模板包相同的模板,但具有更新的包。

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;
}

关于sass - 将 sass 集成到 Angular 模板 Visual Studio 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40966697/

相关文章:

jquery - 如何在按下的按钮上动态设置类?

javascript - 语法错误 : Unexpected token import. Webpack 配置

javascript - 未找到 uws - 使用 SocketIO 的 VueJS

javascript - 带或不带 [] 的 Angular 指令?

angular - 具有条件 <optgroup> 的动态 <select><option> 作为 ng-container 不工作

angular - 带有用户单击选定组件的动态选项卡

javascript - 内部错误 : Invalid UTF-8 - Sass & Gulp

css - 如何组合:hover with :not()?

css - 将 scss 文件添加到 Stackblitz

javascript - 无法将函数导入 Vue.js 单文件组件