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