🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

node-file-path-loader

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-file-path-loader

A webpack loader that get the absolute path of file imported at runtime.

1.0.1
latest
Source
npm
Version published
Weekly downloads
9
800%
Maintainers
1
Weekly downloads
 
Created
Source

node-file-path-loader

Actions Status

A webpack loader that get the absolute path of file imported at runtime.

Why?

This is useful when you are using webpack to build your Node.js/Electron project and just want the absolute path of the file instead of contents. For example, use this loader to get your absolute resources path in Electron at runtime.

import iconPath from "@/resources/image/icon.ico";

const win = new BrowserWindow({ icon: iconPath });

Another scenario is that if you're using typescript to write your worker file, it would be much easier to load your worker file by using ts-loader with this loader.

import compiledWorkerPath from "node-file-path-loader!ts-loader!./worker.ts";

const worker = new Worker(workerPath);

Notification

  • This loader is only works in Node.js environments, like Node.js/Electron.

Installation

npm install node-file-path-loader

Necessary webpack configurations

You need to set webpack target to node and disable mocking of __dirname.

// webpack.config.js
module.exports = {
  target: "node",
  node: {
    __dirname: false,
  },
};

Options

outputPath

Type: String Default: undefined

Specify a filesystem path where the target file(s) will be placed.

Keywords

nodejs

FAQs

Package last updated on 14 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts