├── .gitignore ├── .github └── FUNDING.yml ├── index.js ├── package.json └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: localjo 2 | patreon: localjo 3 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const { exec } = require('child_process'); 2 | const loaderUtils = require('loader-utils'); 3 | 4 | module.exports = function(source) { 5 | const callback = this.async(); 6 | const { script, ...options } = loaderUtils.getOptions(this); 7 | const command = exec(script, options, function(err, result) { 8 | if (err) return callback(err); 9 | callback(null, result); 10 | }); 11 | command.stdin.write(source); 12 | command.stdin.end(); 13 | }; 14 | module.exports.raw = true; 15 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "shell-loader", 3 | "version": "1.2.1", 4 | "description": "A Webpack loader that runs an arbitrary script on matching files", 5 | "keywords": [ 6 | "webpack", 7 | "webpack-loader", 8 | "loader", 9 | "bash", 10 | "bash-script", 11 | "shell", 12 | "shell-script" 13 | ], 14 | "main": "index.js", 15 | "scripts": { 16 | "test": "echo \"Error: no test specified\" && exit 1" 17 | }, 18 | "repository": { 19 | "type": "git", 20 | "url": "https://github.com/localjo/shell-loader.git" 21 | }, 22 | "author": "josiah.sprague@gmail.com", 23 | "license": "MIT", 24 | "dependencies": { 25 | "loader-utils": "^1.1.0" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![NPM Status](https://img.shields.io/npm/v/shell-loader.svg?style=flat)](https://www.npmjs.com/package/shell-loader) 2 | 3 |
4 | 5 | 6 | 7 |

Shell Loader

8 |
9 | 10 | A [Webpack](https://github.com/webpack/webpack) loader for running arbitrary shell scripts when loading files. 11 | 12 | ## Install 13 | 14 | ```bash 15 | npm install --save-dev shell-loader 16 | ``` 17 | 18 | ## Usage 19 | 20 | [Documentation: Using loaders](https://webpack.js.org/loaders/) 21 | 22 | Add shell-loader your Webpack configuration object, setting `options.script` to the shell script you want to run on each file. Example; 23 | 24 | ```javascript 25 | module: { 26 | rules: [ 27 | { 28 | test: /.*\.css$/, 29 | use: [ 'css-loader', { loader: 'shell-loader', options: { 30 | script: 'postcss --use autoprefixer' 31 | }} ] 32 | } 33 | ] 34 | } 35 | ``` 36 | --------------------------------------------------------------------------------