1

我们在处理@importsymfony2 中另一个包的 scss 文件时遇到了麻烦。

  • 源代码(hg repo)/files/...位于机器 A 中。
  • 在开发中,apache 从/var/www/...机器 A 提供服务,链接/files/...机器 A。
  • 在生产中,apache 从/var/www/...机器 B 中提供服务,其中包含源文件的副本

让我们关注一个Layout.scss包含颜色和尺寸定义的文件。这些是我的路径:

# Source code (machine A)
xavi@bromo$ cd /files/custom_www/guparty/workspace/guparty/Applications/Common/bundles/LayoutBundle/Resources/public/Sass
xavi@bromo$ ls -l Layout.scss
-rw-rw-r-- 1 xavi xavi 7528 2013-03-28 12:18 Layout.scss

# Devel (machine A)
xavi@bromo$ cd /var/www/guparty/workspace/www/frontend/src/gUparty/
xavi@bromo$ ls -l Common
lrwxrwxrwx 1 xavi xavi 71 2013-03-28 12:26 Common -> /files/custom_www/guparty/workspace/guparty/Applications/Common/bundles

# Production (machine B)
ubuntu@ProductionLarge1$ cd /var/www/www.guparty.com/src/gUparty/
ubuntu@ProductionLarge1$ ls -ld Common/
drwxr-xr-x 21 www-data www-data 4096 2013-03-28 07:35 Common/

现在让我们考虑Test.scss将包含前一个文件的文件:

# Seen from the source code point of view:
/files/custom_www/guparty/workspace/guparty/Applications/FrontEnd/bundles/TestingBundle/Resources/public/Sass/Test.scss

# Seen from the devel apache point of view (links to the one above):
/var/www/guparty/workspace/www/frontend/src/gUparty/FrontEnd/TestingBundle/Resources/public/Sass/Test.scss

# Seen from the production apache point of view:
/var/www/www.guparty.com/src/gUparty/FrontEnd/TestingBundle/Resources/public/Sass/Test.scss

Test.scss文件以@import这样的指令开头:

@import "../../../../../../../src/gUparty/Common/LayoutBundle/Resources/public/Sass/Layout.scss";

麻烦

从包含文件副本的生产机器上看,它就像一个魅力。

尽管如此,当从开发机器运行时,我希望它能够工作,因为相对路径是相同的。相反,操作系统不会显示链接到 apache/php 的文件,并且似乎资产“需要知道”真实路径。

在开发中,导入失败,如果我把它@import改成这个,它工作正常:

@import "../../../../../../../Applications/Common/bundles/LayoutBundle/Resources/public/Sass/Layout.scss";

我看到的解决方案,但不知道如何实施

a)也许我可以配置一些东西,以便 PHP 看到“相对路径而不映射符号链接”。

b)也许我可以将parameters.ini或类似文件中的“变量”传递到.scss文件中,这样我就可以“发现”我是否处于“链接模式”或“复制模式”并@import使用一个路径或另一个。

有什么方法可以实现a或b?这两种策略之间有什么偏好吗?有什么替代策略吗?

谢谢!哈维。

4

1 回答 1

0

Both solutions are possible.

a) Maybe I could configure something so the PHP sees the "relative paths without demapping the symlinks".

Make sure your Apache configuration has FollowSymLinks enabled and PHP configuration has all the projects directories in the include_path.

b) Maybe I can pass a "variable" from the parameters.ini or similar into the .scss file so I can "discover" if I'm in "linked mode" or "copied mode" and make the @import to use one path or the other.

Create a custom SASS function that returns different result depending on from what project it is called. This will let importing different paths from public/sass/upgrade/index.scss depending on which project you're compiling.

See Compass: Importing files from another project directory for details on both.

于 2013-03-28T15:37:05.943 回答