taro 在 sass 中通过别名(@ 或 ~)引用需要指定路径


1.在 sass 中通过别名(@ 或 ~)引用需要指定路径

config/index.js

const path = require('path')

// NOTE 在 sass 中通过别名(@ 或 ~)引用需要指定路径
const sassImporter = function(url) {
  if (url[0] === '~' && url[1] !== '/') {
    return {
      file: path.resolve(__dirname, '..', 'node_modules', url.substr(1))
    }
  }

  const reg = /^@styles\/(.*)/
  return {
    file: reg.test(url) ? path.resolve(__dirname, '..', 'src/styles', url.match(reg)[1]) : url
  }
}

2.调用

const config = {
  plugins: {
    sass: {
      importer: sassImporter
    }
  },
  h5: {
    sassLoaderOption: {
      importer: sassImporter
    }
  },
}

.


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM