Skip to content

Commit

Permalink
+
Browse files Browse the repository at this point in the history
  • Loading branch information
Dryymoon committed Nov 28, 2020
1 parent e2efb06 commit 87f9516
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
55 changes: 54 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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

<!-- Badges -->
[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
23 changes: 23 additions & 0 deletions nuxt-resolve-url-loader.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
};
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}

0 comments on commit 87f9516

Please sign in to comment.