links-state-replacer

Adds and removes suffixes (example: .min) in the path to mount files depending on the variable passed or the values ​​passed to --env (dev or prod) # ? ! ! # The package is still under development! # It doesn't work. # You can save to bookmarks!

Usage no npm install needed!

<script type="module">
  import linksStateReplacer from 'https://cdn.skypack.dev/links-state-replacer';
</script>

README

gulp-links-state-replacer

Adds and removes suffixes (example: .min) in the path to mount files depending on the variable passed or the values ​​passed to --env (dev or prod)

! ! !

The package is still under development!

It doesn't work.

You can save to bookmarks!

! ! !

Default options

let options = {
  env: 'dev',
  files: [],
  exceptions: {},
  patterns: {
    link: '<link*href=#%#*>',
    script: '<script*src=#%#*></script>'
  },
  rules: {
    suff: {
      link: {
        'dev': '',
        'prod': 'min'
      },
      script: {
        'dev': '',
        'prod': 'min'
      }
    }
  }
}

Explanation of options

  • env (default: 'dev' ) -- pass a string with the name of your development mode.

  • files (default: [] ) -- send a array of files to be processed.

{
  files: [
    '/path/index.html'
  ]
}
  • exceptions (default: {} ) -- exceptions means ignoring in the path file (link, src or other pattern), pass the object.
{
  exceptions: { 
    'index.html': {
      link: [
        'assets/css/style.min.css'
      ],
      script: [
        'assets/js/main.min.js' 
      ],
      custom: [
        'assets/test.custom'
      ]
    }
  }
}

You can see the following:

  1. Ignoring will be done in the index .html file.
  2. In link, script and custom patterns.
  3. Only in patterns that contain the following paths with file names: style.min.css, main.min.js, test.custom.

Read more about patterns.

  • patterns (default: object ) -- here are the tags between which you want to look for the path attribute.

    To use a pattern in settings, you must create one!
{
  patterns: {
    link: '<link*href=#%#*>',
    script: '<script*src=#%#*></script>'
  }
}

Symbols of patterns

To use the following characters as plain text add an inverted slash.
Using the following characters in the path will break the program!

* - zero or more characters to skip to the next symbol.
% - the file path specified in the attribute.
# - a symbol that includes single or double quotes.

To use only single or binary quotation marks, use their symbol instead of the grid.

Let's cut out one of the patterns and see what's in it.

<script    - simple text

*          - any number of characters to the next plain text

src=       - simple text

#          - single or double quotes

%          - file path

#          - single or double quotes

*          - any number of characters to the next plain text

></script> - simple text

You can use other types of patterns, but the package was tested only on html and custom tags.

  • rules (default: object ) -- if the files match the pattern, the suffix is added or removed depending on the mode.
    • suff (deafult: object ) -- depending on the mode, the suffix is added or removed.
{
  rules: {
    suff: {
      '*': {
        'dev': '',
        'prod': 'min'
      },
    }
  }
}

The sign * means - all patterns. You can specify separately for each pattern.

To write a rule for a pattern, you need to create it! Read about creating a pattern above.

Overwrite suffix rules for a file


To overwrite rules for a file, you must specify an array instead of a string.

{
  files: {
    ['path/overwrited.html', {
      suff: {
        link: {
          'dev': 'min',
          'prod': ''
        }
      }
    }]
  }
}

What we did:

  1. Rewrote the rules for the link. Now when env is equal to dev the suffix min will be added, and when min, it will be removed.

To overwrite all suffix patterns, use *.

{
  files: {
    ['path/overwrited.html', {
      suff: {
        '*': {
          'dev': 'min',
          'prod': ''
        }
      }
    }]
  }
}

How to run it?

soon...

How to work with gulp?

soon...

How to manage extensions?

soon...

How to debug it?

soon...

If you think that the package lacks functionality and want new versions, write here: vv.programist@gmail.com