Import regular CSS file in SCSS file?

后端 未结 13 1711
旧巷少年郎
旧巷少年郎 2020-11-22 06:19

Is there anyway to import a regular CSS file with Sass\'s @import command? While I\'m not using all of the SCSS syntax from sass, I do still enjoy it\'s combini

13条回答
  •  猫巷女王i
    2020-11-22 06:29

    Simple workaround:

    All, or nearly all css file can be also interpreted as if it would be scss. It also enables to import them inside a block. Rename the css to scss, and import it so.

    In my actual configuration I do the following:

    First I copy the .css file into a temporary one, this time with .scss extension. Grunt example config:

    copy: {
        dev: {
            files: [
                {
                    src: "node_modules/some_module/some_precompiled.css",
                    dest: "target/resources/some_module_styles.scss"
                }
            ]
        }
    }
    

    Then you can import the .scss file from your parent scss (in my example, it is even imported into a block):

    my-selector {
      @import "target/resources/some_module_styles.scss";
      ...other rules...
    }
    

    Note: this could be dangerous, because it will effectively result that the css will be parsed multiple times. Check your original css for that it contains any scss-interpretable artifact (it is improbable, but if it happen, the result will be hard to debug and dangerous).

提交回复
热议问题