删除Drupal中的默认CSS导入和JS文件

时间:2017-05-19 08:35:00

标签: css drupal drupal-7

我正在构建我的第一个Drupal主题并发现了一些令人震惊的东西。 Drupal 7默认导入10个CSS文件。

public GridDataSource getAdminsSource() {
        return new HibernateGridDataSource(session, Admin.class);
}

然后这也包括在内(不确定为什么或它做什么)

<style type="text/css" media="all">
@import url("http://localhost/drupal/modules/system/system.base.css?oq6xx1");
@import url("http://localhost/drupal/modules/system/system.menus.css?oq6xx1");
@import url("http://localhost/drupal/modules/system/system.messages.css?oq6xx1");
@import url("http://localhost/drupal/modules/system/system.theme.css?oq6xx1");
</style>
<style type="text/css" media="all">
@import url("http://localhost/drupal/modules/comment/comment.css?oq6xx1");
@import url("http://localhost/drupal/modules/field/theme/field.css?oq6xx1");
@import url("http://localhost/drupal/modules/node/node.css?oq6xx1");
@import url("http://localhost/drupal/modules/search/search.css?oq6xx1");
@import url("http://localhost/drupal/modules/user/user.css?oq6xx1");
</style>
<style type="text/css" media="all">
@import url("http://localhost/drupal/themes/stark/layout.css?oq6xx1");
</style>

我正在从头开始构建一个简单的Drupal网站,并且在前端不需要那些2000行的css代码。如何进行并将其全部删除?我只需要我的custom-style.css文件,就是这样。

1 个答案:

答案 0 :(得分:1)

您可以使用hook_css_alter api删除核心和共享模块的默认css文件。 https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_css_alter/7.x

对于Javascript,请检查此hook_js_alter:https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_js_alter/7.x

例如:

<?php
            function YOUR_THEME_css_alter(&$css) {

            // Remove Drupal core css

            $exclude = array(
            'modules/aggregator/aggregator.css' => FALSE,
            'modules/block/block.css' => FALSE,
            'modules/book/book.css' => FALSE,
            'modules/comment/comment.css' => FALSE,
            'modules/dblog/dblog.css' => FALSE,
            'modules/field/theme/field.css' => FALSE,
            'modules/file/file.css' => FALSE,
            'modules/filter/filter.css' => FALSE,
            'modules/forum/forum.css' => FALSE,
            'modules/help/help.css' => FALSE,
            'modules/menu/menu.css' => FALSE,
            'modules/node/node.css' => FALSE,
            'modules/openid/openid.css' => FALSE,
            'modules/poll/poll.css' => FALSE,
            'modules/profile/profile.css' => FALSE,
            'modules/search/search.css' => FALSE,
            'modules/statistics/statistics.css' => FALSE,
            'modules/syslog/syslog.css' => FALSE,
            'modules/system/admin.css' => FALSE,
            'modules/system/maintenance.css' => FALSE,
            'modules/system/system.css' => FALSE,
            'modules/system/system.admin.css' => FALSE,
            'modules/system/system.base.css' => FALSE,
            'modules/system/system.maintenance.css' => FALSE,
            'modules/system/system.messages.css' => FALSE,
            'modules/system/system.menus.css' => FALSE,
            'modules/system/system.theme.css' => FALSE,
            'modules/taxonomy/taxonomy.css' => FALSE,
            'modules/tracker/tracker.css' => FALSE,
            'modules/update/update.css' => FALSE,
            'modules/user/user.css' => FALSE,
            'misc/vertical-tabs.css' => FALSE,

            // Remove contrib module CSS
            drupal_get_path('module', 'views') . '/css/views.css' => FALSE, );
            $css = array_diff_key($css, $exclude);

            }
            ?>