當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript node-sass.render函數代碼示例

本文整理匯總了TypeScript中node-sass.render函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript render函數的具體用法?TypeScript render怎麽用?TypeScript render使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了render函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: Promise

  return new Promise((resolve, reject) => {

    sassConfig.omitSourceMapUrl = true;

    if (sassConfig.sourceMap) {
      sassConfig.sourceMap = basename(sassConfig.outFile);
      sassConfig.sourceMapContents = true;
    }

    nodeSassRender(sassConfig, (sassError: SassError, sassResult: Result) => {
      const diagnostics = runSassDiagnostics(context, sassError);

      if (diagnostics.length) {
        printDiagnostics(context, DiagnosticsType.Sass, diagnostics, true, true);
        // sass render error :(
        reject(new BuildError());

      } else {
        // sass render success :)
        renderSassSuccess(context, sassResult, sassConfig).then(outFile => {
          resolve(outFile);

        }).catch(err => {
          reject(new BuildError(err));
        });
      }
    });
  });
開發者ID:Kode-Kitchen,項目名稱:ionic-app-scripts,代碼行數:28,代碼來源:sass.ts

示例2: Promise

  return new Promise((resolve, reject) => {

    sass.render(sassOpts, (err, result) => {
      if (err) {
        reject(err);
      } else {
        resolve(result.css.toString());
      }
    });
  });
開發者ID:davidenke,項目名稱:ng-packagr,代碼行數:10,代碼來源:assets.ts

示例3: Promise

    return new Promise((resolve, reject) => {
        render({
            file: inFile,
            outputStyle: 'nested',
            outFile: outFile,
            sourceMap: false,
        }, (err, result) => {
            if (err)
                reject(err);
            else
                resolve(result);
        });

    });
開發者ID:danelkhen,項目名稱:desktopbrowser,代碼行數:14,代碼來源:sass.ts

示例4: Promise

  return new Promise((resolve, reject) => {
    sass.render({
      file,
      sourceMap: false
    }, (err, result) => {
      if (err) {
        return reject(`failed to compile ${file}: ${err}`);
      }

      const css = result.css.toString();

      postcss([autoprefixer({browsers: ['last 2 versions']}), cssnano])
        .process(css)
        .then(postResult => {
          postResult.warnings().forEach(warn => {
              console.warn(warn.toString());
          });

          // do not write to file if output is identical to previous version
          const productionCss = postResult.css.toString();
          if (resourceChecksum.update(checksums, path.basename(outputFile), productionCss)) {
            console.log(`[scss]:${file}`);

            fs.writeFile(outputFile, productionCss, werr => {
              if (werr) {
                return reject(`faile to write css file: ${outputFile}: ${werr}`);
              }

              resolve(`${file} compiled`);
            });
          } else {
            console.log(`[unchanged]:${file}`);
            resolve(`${file} unchanged`);
          }
        });
    });
  });
開發者ID:cpylua,項目名稱:cheli.im,代碼行數:37,代碼來源:styles.ts

示例5: function

sass.render({
  file: '/path/to/myFile.scss',
  data: 'body{background:blue; a{color:black;}}',
  importer: function(url, prev, done) {
    // url is the path in import as is, which libsass encountered.
    // prev is the previously resolved path.
    // done is an optional callback, either consume it or return value synchronously.
    // this.options contains this options hash, this.callback contains the node-style callback
    someAsyncFunction(url, prev, function(result) {
      done({
        file: result.path, // only one of them is required, see section Sepcial Behaviours.
        contents: result.data
      });
    });
    // OR
    var result = someSyncFunction(url, prev);
    return { file: result.path, contents: result.data };
  },
  includePaths: ['lib/', 'mod/'],
  outputStyle: 'compressed'
}, function(error, result) { // node-style callback from v3.0.0 onwards
  if (error) {
    console.log(error.status); // used to be "code" in v2x and below
    console.log(error.column);
    console.log(error.message);
    console.log(error.line);
  }
  else {
    console.log(result.css.toString());

    console.log(result.stats);

    console.log(result.map.toString());
    // or better
    console.log(JSON.stringify(result.map)); // note, JSON.stringify accepts Buffer too
  }
});
開發者ID:CNManning,項目名稱:DefinitelyTyped,代碼行數:37,代碼來源:node-sass-tests.ts

示例6: done

        return;
      }
      accum = accum + $n.getValue();
    }
    done(sass.types.Number(accum, unit));
  }
};

const asyncFunctions: Record<string, sass.AsyncSassFunction> = {...asyncFunction, ...asyncVarArg};

const functions: sass.FunctionDeclarations = {...syncFunctions, ...asyncFunctions};

sass.render({
  file: '/path/to/myFile.scss',
  data: 'body{background:blue; a{color:black;}}',
  functions,
  importer: [anotherAsyncImporter, asyncImporter, syncImporter],
  includePaths: ['lib/', 'mod/'],
  outputStyle: 'compressed'
}, handleAsyncResult);

// OR

sass.render({
  file: '/path/to/myFile.scss',
  data: 'body{background:blue; a{color:black;}}',
  importer: asyncImporter,
  includePaths: ['lib/', 'mod/'],
  outputStyle: 'compressed'
}, handleAsyncResult);

// OR
開發者ID:CNBoland,項目名稱:DefinitelyTyped,代碼行數:32,代碼來源:node-sass-tests.ts

示例7: function

sass.render({
  file: '/path/to/myFile.scss',
  data: 'body{background:blue; a{color:black;}}',
  importer: function(url, prev, done) {
    someAsyncFunction(url, prev, function(result) {
      if (result == null) {
        // return null to opt out of handling this path
        // compiler will fall to next importer in array (or its own default)
        return null;
      }
      // only one of them is required, see section Sepcial Behaviours.
      done({ file: result.path });
      done({ contents: result.data });
    });
  },
  includePaths: ['lib/', 'mod/'],
  outputStyle: 'compressed'
}, function(error, result) { // node-style callback from v3.0.0 onwards
  if (error) {
    console.log(error.status, error.column, error.message, error.line);
  }
  else {
    console.log(result.stats);
    console.log(result.css.toString());
    console.log(result.map.toString());
    // or better
    console.log(JSON.stringify(result.map)); // note, JSON.stringify accepts Buffer too
  }
});
// OR
開發者ID:AbraaoAlves,項目名稱:DefinitelyTyped,代碼行數:30,代碼來源:node-sass-tests.ts

示例8: Promise

 return new Promise((resolve, reject) => {
   render(opts, (err, res) => {
     if (err) return reject(err);
     return resolve(res.css.toString("utf8"));
   });
 });
開發者ID:tbtimes,項目名稱:lede,代碼行數:6,代碼來源:SassCompiler.ts

示例9: renderFullPage

            let html = renderFullPage(
                css,
                renderToStaticMarkup(result.root),
                JSON.stringify(state)
            );

            res.send(html);

        } else {
            next();
        }

    };
}

sass.render({
  file: "./site.scss"
}, (error, result) => {
    if (error !== undefined) {
        let handleRender = getHandleRender(result.css.toString("utf8"));
        let app = express();
        let port = 3000;
        app.use(handleRender);
        app.use("/dist", express.static("dist"));
        app.listen(port);
    }
});

console.log("Starting up http-server on: http:127.0.0.1:3000");
開發者ID:redux-bootstrap,項目名稱:redux-bootstrap-example,代碼行數:29,代碼來源:server.ts


注:本文中的node-sass.render函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。