使用 Webpack 解析 SCSS 全局变量



我在解析 scss 全局变量文件时遇到问题。我正在尝试添加一个 scss 颜色文件,我可以简单地将其全局导入到任何需要的地方。

Webpack 1 配置:

  module: {
    loaders: [
      {
        test: /.scss$/,
        loader: 'style' +
        '!css' +
          '?sourceMap' +
          '&modules' +
          '&importLoaders=1' +
          '&localIdentName=[local]__[hash:base64:4]' +
        '!sass' +
          '?sourceMap'
      }
    ]
  },
  sassLoader: {
    includePaths: [
        path.resolve(__dirname, '../src/<path to stylesheets>/themes')
      ]
  },

萨斯文件

@import "colors";
.add {
  background: $button-inactive-state;
}

错误代码(某些个人物品已编辑(

./~/css-loader?sourceMap&modules&importLoaders=1&localIdentName=[local]__[hash:base64:4]!./~/sass-loader/lib/loader.js?sourceMap!./src/<path to file>/toggle-item-button/item-icon.scss
Module build failed: 
@import "colors";
^
      File to import not found or unreadable: colors
Parent style sheet: stdin
      in /Users/<me>/Checkouts/<my project>/src/<path to file>/toggle-item-button/item-icon.scss (line 1, column 1)
Error: 
@import "colors";
^
      File to import not found or unreadable: colors
Parent style sheet: stdin
      in /Users/<me>/Checkouts/<my project>/src/<path to file>/toggle-item-button/item-icon.scss (line 1, column 1)
  at options.error (/Users/<me>/Checkouts/<my project>/node_modules/node-sass/lib/index.js:286:26)
 @ ./src/<path to file>/toggle-item-button/item-icon.scss 4:14-229

我找到了一个可行的解决方案:

网包配置:

  resolve: {
    alias: {
      themes: path.resolve(__dirname, '../src/<path to stylesheets>/themes')
    },
  },

南海

@import "~themes/colors";

相关内容

  • 没有找到相关文章

最新更新