Skip to content

About

Adds macros to snowpack

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Latest commit

 

History

16 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

snowpack-plugin-macros

This plugin adds basic macros to snowpack.

Usage

Install

npm i --save-dev https://github.com/comcloudway/snowpack-plugin-macros

Config

add this plugin to your Snowpack config:

snowpack.config.js

{
  plugins: [[
    'snowpack-plugin-replace',
    {
      "<matches>": ({results, contents, ext, path})=>""
    },
  ]]
}

The paramter object expects entries of the type: String: Function.

The key is used to create a RegExp which will be used to replace the content of the file. The provided function is an extended replace callback function, with an object as its argument:

{
/// results of regexp replace function
/// will be of following layout:
/// [matches, ...positional_arguments, offset, contents, groups]
/// Find out more: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_function_as_a_parameter
results: [],

/// the content of the file being edited
contents: "",
/// the file extension
/// either .js or .css
ext: "",
/// path to the given file
path: ""
}

The callback function has to return the new string, which shall be used to replace the old value.

Restrictions

This plugin works on the snowpack transform stage, so its only works on *.js or *.css files.

Don't worry about others file like *.ts, *.less, they will be transformed to one of the above by snowpack

Shoutouts

About

Adds macros to snowpack

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages