grunt-contrib-sass:如何动态地将子文件夹添加到目标?

时间:2016-02-15 21:49:31

标签: sass grunt-contrib-sass

我有一个目录结构:

  • views
    • _static_
      • some.js
    • somesass.scss
    • something.jade

我希望做到这样的事情: sass: { dist: { options: { style: 'expanded' }, files: [{ expand: true, cwd: 'views', src: ['*/*.scss'], flatten: true, dest: 'views/*/_static_', ext: '.css' }] } },

如果我只是执行dest: 'views'并删除flatten:true,那么至少将它放在.scss文件所在的同一文件夹中,但我无法弄清楚怎么说“ok ,将“_static_”添加到当前文件的cwd,并将.css放在那里。如何/我可以用grunt-contrib-sass做到这一点?

如果想知道为什么我不只是把所有已编译的CSS都放到一个目录中,那是因为这是我自己的实验服务器,所以我不是在缩小或者其他任何东西。

1 个答案:

答案 0 :(得分:0)

为了让子文件夹进入我必须使用from selenium import webdriver import time txt = open("emails.txt", 'r') chrome_path = r"C:\Users\Skid\Desktop\chromedriver.exe" driver = webdriver.Chrome(chrome_path) for x in range(5): driver.get("https://signup.live.com/signup?wa=wsignin1.0&rpsnv=12&ct=1455592987&rver=6.4.6456.0&wp=MBI_SSL_SHARED&wreply=https%3a%2f%2fmail.live.com%2fdefault.aspx%3frru%3dinbox&id=64855&cbcxt=mai&bk=1455592987&uiflavor=web&uaid=947b22b7c0d249f8ab527df4fb06c828&mkt=EN-US&lc=1033&lic=1") driver.find_element_by_xpath("""//*[@id="memberNameDomain"]""").click() driver.find_element_by_xpath("""//*[@id="CredentialsInputPane"]/fieldset/div[2]/div/div[1]/div/ul/li[2]/a""").click() type_into_email = driver.find_element_by_xpath("""//*[@id="MemberName"]""") type_into_email.send_keys(txt.readline()) refresh = driver.find_element_by_xpath("""//*[@id="FirstName"]""").click() time.sleep(5) error = driver.find_element_by_xpath("""//*[@id="MemberNameError"]""") if error.is_displayed(): print(txt.readline() + "Is taken") else: print(txt.readline() + " Is available") 的路径,但事情并没有像我想象的那样工作。首先,rename: function(dest, src){ .. }不是想要的,所以我们可以通过src获取父目录。另一件需要注意的事情是,flatten内的srcrename:作为文件,即使whatever.css外部定义为src。这对我们有利,但让我失望,因为我希望看到['*/*.scss']。我仍然需要回去做一些工作,但这完成了我的工作:

whatever.scss

最终结果是:

  • sass: { dist: { options: { style: 'expanded' }, files: [{ expand: true, cwd: 'views', src: ['*/*.scss'], rename: function(dest, src) { // src will have .css extension, not scss. var splitPath = src.split('/'); // Leaves the path preceding the filename in splitPath. var filename = splitPath.pop(); // There shouldn't be any other subdirectories, // but added j.i.c. until I can come back to it. var joinedPath = splitPath.join("/"); var customDest = this.cwd + '/' + joinedPath + '/_static_/' + filename; return customDest; }, ext: '.css' }] }
    • views
      • _static_
      • some.js(在运行somesass.css后)自定义位置
    • grunt sass(来源Sass)
    • somesass.scss