我可以在SCSS文件中使用变量吗?

时间:2019-11-13 11:24:04

标签: css variables sass

我正在使用不同的“ SCSS变量文件”(引导程序变量,公司变量,项目变量),因此很容易在其他项目中重复使用它们。但是看来我不能跨文件使用变量。

示例:

  • <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.myeclipse.example</groupId> <artifactId>com.myeclipse.example.id</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>eclipse-plugin</packaging> <properties> <tycho-version>1.3.0</tycho-version> </properties> <repositories> <repository> <id>eclipse-2018-12</id> <layout>p2</layout> <url>https://download.eclipse.org/releases/2018-12/</url> </repository> </repositories> <build> <plugins> <plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>tycho-maven-plugin</artifactId> <version>${tycho-version}</version> <extensions>true</extensions> </plugin> </plugins> </build> </project> 中,我宣布了 [INFO] Adding repository https://download.eclipse.org/releases/2018-12 [ERROR] Internal error: java.lang.RuntimeException: Failed to load p2 repository with ID '2018-12' from location https://download.eclipse.org/releases/2018-12/: Unknown Host: https://download.eclipse.org/releases/2018-12/content.xml: Unknown host download.eclipse.org -> [Help 1] org.apache.maven.InternalErrorException: Internal error: java.lang.RuntimeException: Failed to load p2 repository with ID '2018-12' from location https://download.eclipse.org/releases/2018-12/ at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:120) at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956) at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288) at org.apache.maven.cli.MavenCli.main (MavenCli.java:192) ... Caused by: java.lang.RuntimeException: Failed to load p2 repository with ID '2018-12' from location https://download.eclipse.org/releases/2018-12/ at org.eclipse.tycho.p2.target.TargetPlatformFactoryImpl.loadMetadataRepository (TargetPlatformFactoryImpl.java:302) at org.eclipse.tycho.p2.target.TargetPlatformFactoryImpl.gatherExternalInstallableUnits (TargetPlatformFactoryImpl.java:270) at org.eclipse.tycho.p2.target.TargetPlatformFactoryImpl.createTargetPlatform (TargetPlatformFactoryImpl.java:176) at org.eclipse.tycho.p2.target.TargetPlatformFactoryImpl.createTargetPlatform (TargetPlatformFactoryImpl.java:128) at org.eclipse.tycho.p2.target.TargetPlatformFactoryImpl.createTargetPlatform (TargetPlatformFactoryImpl.java:1) at org.eclipse.tycho.p2.manager.ReactorRepositoryManagerImpl.computePreliminaryTargetPlatform (ReactorRepositoryManagerImpl.java:84) at org.eclipse.tycho.p2.resolver.P2DependencyResolver.computePreliminaryTargetPlatform (P2DependencyResolver.java:224) at org.eclipse.tycho.core.resolver.DefaultTychoResolver.resolveProject (DefaultTychoResolver.java:110) at org.eclipse.tycho.core.maven.TychoMavenLifecycleParticipant.afterProjectsRead (TychoMavenLifecycleParticipant.java:95) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:264) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192) .... Caused by: org.eclipse.equinox.p2.core.ProvisionException: Unknown Host: https://download.eclipse.org/releases/2018-12/content.xml at org.eclipse.equinox.internal.p2.repository.CacheManager.createCache (CacheManager.java:246) at org.eclipse.tycho.p2.remote.RemoteRepositoryCacheManager.createCache (RemoteRepositoryCacheManager.java:67) at org.eclipse.equinox.internal.p2.metadata.repository.SimpleMetadataRepositoryFactory.getLocalFile (SimpleMetadataRepositoryFactory.java:69) at org.eclipse.equinox.internal.p2.metadata.repository.SimpleMetadataRepositoryFactory.load (SimpleMetadataRepositoryFactory.java:89) at org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryManager.factoryLoad (MetadataRepositoryManager.java:63) at org.eclipse.equinox.internal.p2.repository.helpers.AbstractRepositoryManager.loadRepository (AbstractRepositoryManager.java:770) at org.eclipse.equinox.internal.p2.repository.helpers.AbstractRepositoryManager.loadRepository (AbstractRepositoryManager.java:671) at org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryManager.loadRepository (MetadataRepositoryManager.java:110) at org.eclipse.tycho.p2.remote.RemoteMetadataRepositoryManager.loadRepository (RemoteMetadataRepositoryManager.java:61) at org.eclipse.tycho.p2.remote.RemoteMetadataRepositoryManager.loadRepository (RemoteMetadataRepositoryManager.java:53) at org.eclipse.tycho.p2.target.TargetPlatformFactoryImpl.loadMetadataRepository (TargetPlatformFactoryImpl.java:298) at org.eclipse.tycho.p2.target.TargetPlatformFactoryImpl.gatherExternalInstallableUnits (TargetPlatformFactoryImpl.java:270) ... Caused by: java.net.UnknownHostException: download.eclipse.org at java.net.InetAddress.getAllByName0 (InetAddress.java:1280) at java.net.InetAddress.getAllByName (InetAddress.java:1192) at java.net.InetAddress.getAllByName (InetAddress.java:1126) at org.apache.http.impl.conn.SystemDefaultDnsResolver.resolve (SystemDefaultDnsResolver.java:45) at org.apache.http.impl.conn.DefaultClientConnectionOperator.resolveHostname (DefaultClientConnectionOperator.java:263) at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection (DefaultClientConnectionOperator.java:162) at org.apache.http.impl.conn.ManagedClientConnectionImpl.open (ManagedClientConnectionImpl.java:326) at org.apache.http.impl.client.DefaultRequestDirector.tryConnect (DefaultRequestDirector.java:610) at org.apache.http.impl.client.DefaultRequestDirector.execute (DefaultRequestDirector.java:445) at org.apache.http.impl.client.AbstractHttpClient.doExecute (AbstractHttpClient.java:835) at org.apache.http.impl.client.CloseableHttpClient.execute (CloseableHttpClient.java:83) at org.eclipse.ecf.provider.filetransfer.httpclient4.HttpClientFileSystemBrowser.runRequest (HttpClientFileSystemBrowser.java:263) at org.eclipse.ecf.provider.filetransfer.browse.AbstractFileSystemBrowser$DirectoryJob.run (AbstractFileSystemBrowser.java:69) at org.eclipse.core.internal.jobs.Worker.run (Worker.java:63) [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
  • company-variables.scss中,我想像上面的$white: #fff;这样重用上面的变量
  • 我收到以下错误:project-variables.scss

我这样加载文件:

$body-color: darken($white, 20%);

路径正确。

我对SCSS很陌生。知道我在做什么错吗?或者这不可能/不是要走的路吗?

1 个答案:

答案 0 :(得分:0)

如果要使用它,应该导入@import“ company-variables”;到@import“项目变量”中;

或者仅使用引导程序中的默认白色,例如: 变暗(主题颜色(“白色”),20%);