1.0.2 • Published 7 years ago

pug-dep-loader v1.0.2

Weekly downloads
5
License
MIT
Repository
github
Last release
7 years ago

Pug Dependency Loader

Author: https://github.com/steelstring94

Description

Pug Dependency Loader (pug-dep-loader) is a Webpack loader designed to process Pug templates and output Pug files where dependencies, such as images, have been automatically processed by Webpack. It makes available a depload() function in your Pug templates to which you pass a file path.

An example use case is to automatically load only the images your template actually uses, and automatically copy them to your dist folder in the appropriate location as defined by file-loader. pug-dep-loader also supports integration with url-loader and will automatically replace depload() calls with data URLs if url-loader is in use and returns a data URL.

Versions follow the SemVer pattern.

Usage:

In your Pug templates, wherever you would normally put a file URL, simply use depload(<PATH_TO_FILE>)

For example: img(src="depload(images/image.jpg)")

You need not surround the depload() file path with quotes, although the loader will still function as expected if you do.

pug-dep-loader will have that file copied as you specify with file-loader, or replace the depload() call with a data URL returned by url-loader. It is up to you to make sure you have whichever of these installed that you require.

pug-dep-loader will return a string to Webpack that contains your Pug file with all depload() calls replaced with the appropriate file path or data URL. You should pass the output of pug-dep-loader to file-loader in order to have it written to disc.

Options:

You may pass pug-dep-loader an options object with the following properties:

root: String - Resource root of your dependent files. For example, if in your Pug you have img(src="depload(images/image.jpg)") and that path is /src/images/image.jpg relative to the root of your project, then you should set this option to ./src (so relative to the location of webpack.config.js). Trailing slash will be added automatically if not present.

If you do not set this option, the resource root will be assumed to be a sub-directory of the location of whatever Pug file is presently being processed. Unless you have a very peculiar (and probably inefficient) organization of your project, this is virtually guaranteed to cause you problems, so it's advised you ensure to explicitly set a resource root.

outputPath: String - Custom path with which to replace the depload() calls. Does not affect where the depload()ed files are output. Trailing slash will be added automatically if not present. If unspecified, path will not be changed.

License:

MIT License

Copyright (c) 2017 https://github.com/steelstring94

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

pug-dep-loader