prepost-loader

1.0.1 • Public • Published

prepost loader for webpack

A loader add prefix or postfix string to source file for webpack. based on imports-loader

Installation

npm install prepost-loader

Usage Examples

  1. Auto import React and React.Component for all .jsx files.
// ./webpack.config.js
 
module.exports = {
    ...
    module: {
        loaders: [
            {
                test: /\.jsx$/,
                loader: "prepost",
                query: {
                  prefix: ['var React = require("react");', 'var Component = React.Component;'],
                  postfix: ''
                }
            }
        ]
  };
  1. If you have tow files: /path/to/foo.jsx and /path/to/foo.sass. Every time you require foo.jsx, you want auto require foo.sass, then you can write something like this in webpack config file.
// ./webpack.config.js
 
module.exports = {
    ...
    module: {
        loaders: [
            {
                test: /\.jsx$/,
                loader: "prepost",
                query: {
                  autoRequireExtensions: ['sass', 'scss', 'css']
                }
            }
        ]
  };

Documentation: Using loaders

License

MIT

Package Sidebar

Install

npm i prepost-loader

Weekly Downloads

2

Version

1.0.1

License

MIT

Last publish

Collaborators

  • qiu8310