npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@rksan/path-alias

v1.0.0

Published

Reads the path-alias property in any config file and helps resolve it to an absolute path.

Downloads

5

Readme

Coverage Status

path-alias

任意の config file にある path-alias プロパティを読み込み、絶対パスに解決する手助けをします。

例えば、babel.configaliasプロパティは、相対パスでの記述が推奨されますが、同パスを記述するであろうvue.configaliasプロパティは絶対パスで記述しないと正常に動作しない場合があります。

こうした場合、2種類の config file を開発者が管理する必要がありますが、そのうち何処に設定していたのか忘れてしまうことが多々あります。

そこで、module の pash aliase を任意の別ファイルで管理し、相対パスと絶対パスを相互に変換できるプラグインがあったら便利だなぁとpath-aliasを作成しました。

インストール

npm install --save-dev @rksan/path-alias

使用方法

1. config file の作成

まず任意のファイルとしてaliases.jsonを作成します。 ファイルの名前も任意です。

次にbabel.configが保持するであろうaliasプロパティを記述します。内容も任意です。

aliase.json

{
  "root": [".", "./src"],
  "alias": {
    "~": ".",
    "@": "./src"
  }
}

2. プラグインへの読み込み

以下、例として、babel.configvue.configでの使用方法を説明します。(@babel-plugin-module-resolverの利用が前提)

babe.config.js

// 本モジュールの読み込み
const pathAliase = require("path-alias");

// 参照する config の変更
pathAliases.setConfig({
  // アプリケーションルートパス
  appRootPath: __dirname,
  // 任意の config file がある、アプリケーションルートパスからの相対パス
  config: "./aliases.json".
});

// 相対パスのまま参照
const config = pathAliases.toJSON();

// babel.config に割当する
module.exports = {
  ...

  "plugins": [
    ["module-resolver", {
      "root": config.root,
      "alias": config.alias // { "~", "@" }
    }]
  ]

  ...
}

vue.config.js

// 本モジュールの読み込み
const pathAliase = require("path-alias");

// 設定の変更
pathAliases.setConfig({
  // アプリケーションルートパス
  appRootPath: __dirname,
  // 任意の config file がある、アプリケーションルートパスからの相対パス
  config: "./aliases.json".
});

// 絶対パスへ解決
const config = pathAliases.resolve();

const { defineConfig } = require("@vue/cli-service");

module.exports = defineConfig({
  ...
  configureWebpack: (config) => {
    config = {
      resolve: {
        alias: config.alias  // { "~", "@" }
    };

    return config;
    }
  },
  ...
});

LICENSE

MIT

更新履歴

v1.0.0

  • 正式リリース
  • install を追記
  • LICENSE を追記

v0.0.2

  • package name を変更

v.0.0.0

  • 新規