Skip to content

Loader for Webpack to append and prepend text to files. The only one that still works.

License

Notifications You must be signed in to change notification settings

Kir-Antipov/append-prepend-loader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

append-prepend-loader

npm: append-prepend-loader License

Loader for Webpack to append and prepend text to files. The only one that still works.

Installation

  • With npm:
npm i --save-dev append-prepend-loader
  • With yarn:
yarn add --dev append-prepend-loader

Usage

webpack.config.js

module.exports = {
    module: {
        rules: [
            {
                test: /\.js$/,
                use: [
                    {
                        loader: "append-prepend-loader",
                        options: {
                            prepend: "console.log('Top');",
                            append: "console.log('Bottom');",
                        }
                    },
                ]
            },
        ]
    }
};

append and prepend can be one of the T:

  • string
  • function: (content: string, map: SourceMap, meta: Meta) => T
  • asynchronous function: (content: string, map: SourceMap, meta: Meta) => Thenable<T>
  • callback function: (content: string, map: SourceMap, meta: Meta, callback: (error, result) => void) => void
  • Thenable<T>
  • object (which will be converted to json)

More complex example:

{
   loader: "append-prepend-loader",
   options: {
       prepend: async (content) => {
           const header = await foo(content);
           return header.trim();
       },
       append: (content, map, meta, callback) => {
           baz(content, footer => callback(null, footer.trim()))
       },
   }
}

About

Loader for Webpack to append and prepend text to files. The only one that still works.

Resources

License

Stars

Watchers

Forks

Releases

No releases published