From 87f9516f8119adb2cbc27646ee2572d728496ecb Mon Sep 17 00:00:00 2001 From: dryymoon Date: Sat, 28 Nov 2020 15:30:21 +0200 Subject: [PATCH] + --- .gitignore | 1 + README.md | 55 +++++++++++++++++++++++++++++++++++++- nuxt-resolve-url-loader.js | 23 ++++++++++++++++ package-lock.json | 13 +++++++++ package.json | 25 +++++++++++++++++ 5 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 nuxt-resolve-url-loader.js create mode 100644 package-lock.json create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/README.md b/README.md index 043bfe5..9ade7af 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,55 @@ # nuxt-resolve-url-loader -Nuxt module for adding resolve-url-loader to webpack config. + +[![npm downloads][npm-downloads-src]][npm-downloads-href] +[![License][license-src]][license-href] + +> Easy add 'resolve-url-loader' to Nuxt.js webpack config + +## Requirements + +You need to ensure that you have `resolve-url-loader` installed: + +```bash +npm install --save-dev resolve-url-loader +``` + +## Setup + +1. Add `nuxt-resolve-url-loader` dependency to your project + +```bash +npm install --save-dev nuxt-resolve-url-loader +``` + +2. Add `nuxt-resolve-url-loader` to the `buildModules` section of `nuxt.config.js` + +```js +export default { + buildModules: [ + // Simple usage + 'nuxt-resolve-url-loader', + + // With options + ['nuxt-resolve-url-loader', { /* options for resolve-url-loader */ }] + ] +} +``` + +:warning: If you are using Nuxt **< v2.9** you have to install the module as a `dependency` (No `--dev` or `--save-dev` flags) and use `modules` section in `nuxt.config.js` instead of `buildModules`. + +## Options + +See [resolve-url-loader options](https://www.npmjs.com/package/resolve-url-loader#options) for the complete list of options available. These options are passed through to the `resolve-url-loader` directly. + +## License + +[MIT License](./LICENSE) + +Copyright (c) Igor Pylypenko + + +[npm-downloads-src]: https://img.shields.io/npm/dt/nuxt-resolve-url-loader.svg +[npm-downloads-href]: https://npmjs.com/package/nuxt-resolve-url-loader + +[license-src]: https://img.shields.io/npm/l/nuxt-resolve-url-loader.svg +[license-href]: https://npmjs.com/package/nuxt-resolve-url-loader diff --git a/nuxt-resolve-url-loader.js b/nuxt-resolve-url-loader.js new file mode 100644 index 0000000..2473f6a --- /dev/null +++ b/nuxt-resolve-url-loader.js @@ -0,0 +1,23 @@ +const traverse = require('traverse'); + +module.exports = function (options) { + this.extendBuild(function setup(config) { + traverse(config).forEach(function (some) { + if (this.key !== 'loader' || some !== 'sass-loader') return; + + let loaderConfig = this.parent.node; + loaderConfig = { ...loaderConfig, options: { ...loaderConfig.options, sourceMap: true } }; + + this.parent.update(loaderConfig); + + const array = [...this.parent.parent.node]; + + array.splice(this.parent.path.pop(), 0, { + loader: 'resolve-url-loader', + options + }); + + this.parent.parent.update(array); + }); + }); +}; diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..824b60c --- /dev/null +++ b/package-lock.json @@ -0,0 +1,13 @@ +{ + "name": "nuxt-resolve-url-loader", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "traverse": { + "version": "0.6.6", + "resolved": "https://registry.npmjs.org/traverse/-/traverse-0.6.6.tgz", + "integrity": "sha1-y99WD9e5r2MlAv7UD5GMFX6pcTc=" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..75729b6 --- /dev/null +++ b/package.json @@ -0,0 +1,25 @@ +{ + "name": "nuxt-resolve-url-loader", + "version": "1.0.0", + "description": "Nuxt module for adding resolve-url-loader to webpack config.", + "main": "nuxt-resolve-url-loader.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/Dryymoon/nuxt-resolve-url-loader.git" + }, + "author": "Igor Pylypenko", + "license": "MIT", + "bugs": { + "url": "https://github.com/Dryymoon/nuxt-resolve-url-loader/issues" + }, + "homepage": "https://github.com/Dryymoon/nuxt-resolve-url-loader#readme", + "dependencies": { + "traverse": "^0.6.6" + }, + "peerDependencies": { + "resolve-url-loader": "^3.1.2" + } +}