<i id='RFTHG'><tr id='RFTHG'><dt id='RFTHG'><q id='RFTHG'><span id='RFTHG'><b id='RFTHG'><form id='RFTHG'><ins id='RFTHG'></ins><ul id='RFTHG'></ul><sub id='RFTHG'></sub></form><legend id='RFTHG'></legend><bdo id='RFTHG'><pre id='RFTHG'><center id='RFTHG'></center></pre></bdo></b><th id='RFTHG'></th></span></q></dt></tr></i><div id='RFTHG'><tfoot id='RFTHG'></tfoot><dl id='RFTHG'><fieldset id='RFTHG'></fieldset></dl></div>
          <bdo id='RFTHG'></bdo><ul id='RFTHG'></ul>

        <small id='RFTHG'></small><noframes id='RFTHG'>

        <tfoot id='RFTHG'></tfoot>
      1. <legend id='RFTHG'><style id='RFTHG'><dir id='RFTHG'><q id='RFTHG'></q></dir></style></legend>

      2. 如何在 Polymer 组件中使用 Sass

        时间:2023-05-29

          <legend id='jzdlw'><style id='jzdlw'><dir id='jzdlw'><q id='jzdlw'></q></dir></style></legend>
          • <bdo id='jzdlw'></bdo><ul id='jzdlw'></ul>
              <tbody id='jzdlw'></tbody>
            <tfoot id='jzdlw'></tfoot>
            <i id='jzdlw'><tr id='jzdlw'><dt id='jzdlw'><q id='jzdlw'><span id='jzdlw'><b id='jzdlw'><form id='jzdlw'><ins id='jzdlw'></ins><ul id='jzdlw'></ul><sub id='jzdlw'></sub></form><legend id='jzdlw'></legend><bdo id='jzdlw'><pre id='jzdlw'><center id='jzdlw'></center></pre></bdo></b><th id='jzdlw'></th></span></q></dt></tr></i><div id='jzdlw'><tfoot id='jzdlw'></tfoot><dl id='jzdlw'><fieldset id='jzdlw'></fieldset></dl></div>

                <small id='jzdlw'></small><noframes id='jzdlw'>

                  本文介绍了如何在 Polymer 组件中使用 Sass的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我目前使用 Polymer 作为我的前端开发框架.我喜欢萨斯.现在我知道我可以像往常一样创建一个 Sass 文件并导入它.

                  I'm currently using Polymer as my front end development framework. I love SASS. Now I understand I can create a Sass file and import it like I normally would.

                  不过,我已经养成了在我的 Web 组件中使用样式标签的习惯.

                  However, I've really gotten into the habit of using style tags within my web components.

                  基本上,我正在寻找的工作流程是能够在我的 Web 组件中简单地定义一个脚本标签,也许可以添加 type='sass;给它.然后在将文件输出到我的 .tmp 目录之前,让 grunt 编译这些标签中的所有 SASS.

                  Basically the workflow I am looking for is to be able to simply define a script tag within my Web Component maybe add type='sass; to it. Then have grunt go through and compile all of my SASS within those tags before outputting the files to my .tmp directory.

                  像 Grunt 或 Gulp 这样的东西可以实现吗?如果是这样,什么是帮助我实现这一目标的最佳模块?

                  Is something like this achievable with something like Grunt or Gulp? If so what are the best modules to help me achieve this?

                  推荐答案

                  我的实现是基于 Polymer html 文件中的标签替换.我正在使用 gulp 但可以更改为简单地使用 fs.

                  My implementation is based on a replacement of a tag inside the Polymer html file. I'm using gulp but could be changed to use simply fs.

                  文件结构应该是这个例子:

                  The files structure should be as this example:

                  app-view
                   |- app-view.html
                   |- app-view.scss
                  

                  app-view.html:

                  <dom-module id="app-view">
                      <template>
                          <style>
                              <!-- inject{scss} -->
                          </style>
                      </template>
                  </dom-module>
                  

                  app-view.scss:

                  :host{
                      margin-top: 50px;
                      justify-content: center;
                      display: flex;
                  }
                  #container{
                      font-size: 12px;
                      h1{
                          font-size: 20px;
                      }
                  }
                  

                  gulpfile.js:

                  var gulp = require('gulp');
                  var nodeSass = require('node-sass');
                  var path = require('path');
                  var fs = require('fs');
                  var map = require('map-stream');
                  var srcPath = 'src/';
                  var buildPath = 'build/';
                  var buildSrcPath = path.join(buildPath, 'target');
                  
                  gulp.task('processComponents', function () {
                      return gulp.src([srcPath + '/components/**/*.html'])
                          .pipe(map(function (file, cb) {
                              var injectString = '<!-- inject{scss} -->';
                              // convert file buffer into a string
                              var contents = file.contents.toString();
                              if (contents.indexOf(injectString) >= 0) {
                                  //Getting scss
                                  var scssFile = file.path.replace(/.html$/i, '.scss');
                                  fs.readFile(scssFile, function (err, data) {
                                      if (!err && data) {
                                          nodeSass.render({
                                              data: data.toString(),
                                              includePaths: [path.join(srcPath, 'style/')],
                                              outputStyle: 'compressed'
                                          }, function (err, compiledScss) {
                                              if (!err && compiledScss) {
                                                  file.contents = new Buffer(contents.replace(injectString, compiledScss.css.toString()), 'binary');
                                              }
                                              return cb(null, file);
                                          });
                                      }
                                      return cb(null, file);
                                  });
                              } else {
                                  // continue
                                  return cb(null, file);
                              }
                          }))
                          .pipe(gulp.dest(path.join(buildSrcPath, 'components')));
                  });
                  

                  结果:

                  <dom-module id="app-view">
                      <template>
                          <style>
                              :host{margin-top:50px;justify-content:center;display:flex}#container{font-size:12px}#container h1{font-size:20px}
                          </style>
                      </template>
                  </dom-module>
                  

                  这篇关于如何在 Polymer 组件中使用 Sass的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:从 gulp 中使用 browserify 时如何向浏览器公开“要 下一篇:如何使用 gulp-browserify 观看多个文件但只处理一个

                  相关文章

                  最新文章

                • <i id='8onS8'><tr id='8onS8'><dt id='8onS8'><q id='8onS8'><span id='8onS8'><b id='8onS8'><form id='8onS8'><ins id='8onS8'></ins><ul id='8onS8'></ul><sub id='8onS8'></sub></form><legend id='8onS8'></legend><bdo id='8onS8'><pre id='8onS8'><center id='8onS8'></center></pre></bdo></b><th id='8onS8'></th></span></q></dt></tr></i><div id='8onS8'><tfoot id='8onS8'></tfoot><dl id='8onS8'><fieldset id='8onS8'></fieldset></dl></div>

                  1. <legend id='8onS8'><style id='8onS8'><dir id='8onS8'><q id='8onS8'></q></dir></style></legend>

                    1. <tfoot id='8onS8'></tfoot>
                        <bdo id='8onS8'></bdo><ul id='8onS8'></ul>

                      <small id='8onS8'></small><noframes id='8onS8'>