{"id":18962,"library":"apply-loader","title":"apply-loader","description":"Webpack loader that executes an exported JavaScript function (default or module.exports) with optional arguments and returns the exported value. Current stable version 2.0.0, maintained as of last release. Unlike conventional loaders that transform source code, it invokes the target module as a factory function. Supports both webpack 1 and 2 configuration syntax.","status":"active","version":"2.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/mogelbrod/apply-loader","tags":["javascript","webpack","loader","apply"],"install":[{"cmd":"npm install apply-loader","lang":"bash","label":"npm"},{"cmd":"yarn add apply-loader","lang":"bash","label":"yarn"},{"cmd":"pnpm add apply-loader","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This is a webpack loader, not a JS module. It is used in webpack config, not imported in application code.","wrong":"import apply from 'apply-loader';","symbol":"apply-loader","correct":"const apply = require('apply-loader');"},{"note":"In webpack 1, use 'loader'; in webpack 2+, use 'use' with options object.","wrong":"{ test: /\\.js$/, use: 'apply-loader?args[]=1' }","symbol":"Use in webpack config (webpack 1)","correct":"{ test: /\\.js$/, loader: 'apply-loader?args[]=1' }"},{"note":"Webpack 2+ prefers options object over query string.","wrong":"{ test: /\\.js$/, loader: 'apply-loader?args[]=1' }","symbol":"Use in webpack config (webpack 2+)","correct":"{ test: /\\.js$/, use: { loader: 'apply-loader', options: { args: [1] } } }"}],"quickstart":{"code":"// webpack.config.js\nmodule.exports = {\n  entry: './app.js',\n  output: { filename: 'bundle.js' },\n  module: {\n    rules: [\n      {\n        test: /\\.js$/,\n        exclude: /node_modules/,\n        use: {\n          loader: 'apply-loader',\n          options: {\n            args: ['hello', { foo: 'bar' }]\n          }\n        }\n      }\n    ]\n  }\n};\n\n// greet.js (target module)\nfunction greet(greeting, options) {\n  return `${greeting} ${options.foo}`;\n}\nmodule.exports = greet;\n\n// Result: bundle exports 'hello bar'","lang":"javascript","description":"Configures apply-loader to invoke greet.js with arguments and export the return value."},"warnings":[{"fix":"Upgrade to v2.0.0","message":"v2.0.0 stops triggering loader-utils deprecation warning","severity":"breaking","affected_versions":"<2.0.0"},{"fix":"Use options object in webpack config","message":"Query string syntax (e.g., ?args[]=1) is deprecated in webpack 2+","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Ensure your module exports a function as default or module.exports","message":"If the target module exports both default and named, apply-loader calls the default export first","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use options object: { loader: 'apply-loader', options: { args: [1] } }","cause":"Using query string syntax with webpack 2+ without proper encoding or using 'use' array incorrectly.","error":"Error: apply-loader?args[]=1: The provided value \"args[]\" is not a valid request parameter."},{"fix":"Ensure the target module exports a function: module.exports = function(...) {...}","cause":"Target module does not export a function (exports an object, string, etc.).","error":"Module build failed: TypeError: apply is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}