将变量从npm build传递给scss

时间:2020-07-06 11:44:38

标签: webpack sass

我希望将变量从我的构建传递到我们的sass变量。

webpack.config.js:

const glob = require('glob');
const path = require('path');
const loaders = require('./loaders');
const plugins = require('./plugins');

// Loop over all our .scss files.
const mapFilenamesToEntries = pattern => (
  glob
    .sync(pattern)
    .reduce((entries, filename) => {
      const [, name] = filename.match(/([^/]+)\.scss$/)
        if (name.substr(0, 1) === '_') {
       return entries;
      }
    return Object.assign({ [name]: filename }, entries)
  }, {})
);
module.exports = (evt, options) => {
  // options.brand is the variable I want to pass to my scss.
  return {
    stats: {
      children: options.mode == 'development' ? false : true,
    },

    context: path.resolve(__dirname, '../'),

    entry: mapFilenamesToEntries(path.resolve('scss/**/*.scss')),

    output: {
      path: path.resolve('dist'),
      publicPath: path.resolve('images'),
    },

    module: {
      rules: [
        loaders.CSSLoader,
      ]
    },

    plugins: [
      plugins.StyleLintPlugin,
      plugins.FixStyleOnlyEntriesPlugin,
      plugins.MiniCssExtractPlugin,
      plugins.OptimizeCssAssetsPlugin,
    ], 
  }
};

如何传递变量(此处为brand),这实际上是用来从sass构建css文件的?

0 个答案:

没有答案