import { CssType } from "../type/css-type" ; import { replaceLastString } from "../utils/replace-last-string" ; import { Rule , AtRule , Import , Comment , StyleRules , Stylesheet } from 'css' ; author CaMnter
  export function replaceImport ( target , expect , stylesheet ? ) { if ( ! stylesheet ) { return ; } const styleRules = stylesheet . stylesheet ; if ( ! styleRules ) { return ; } const rules = styleRules . rules ; rules . forEach ( ( value ) => { const { type } = value ; if ( 'import' === type ) { const valueImport = value as Import ; const importValue = valueImport . import ; if ( importValue ) { let suffix = '' ; let replace = false ; if ( importValue . endsWith ( `${ target }'` ) ) { suffix = `'` ; replace = true ; } else if ( importValue . endsWith ( `${ target }"` ) ) { suffix = `"` ; replace = true ; } else if ( importValue . endsWith ( `${ target }` ) ) { suffix = '' ; replace = true ; } if ( replace ) { valueImport . import = replaceLastString ( importValue , `${ target }${ suffix }` , `${ expect }${ suffix }` ) ; } } } } ) ; }