Code Monkey home page Code Monkey logo

rollup-sourcemap-path-transform's Introduction

rollup-sourcemap-path-transform

Latest version Dependency status Coverage

Function sourcemapPathTransform for Rollup to rebase sources in source maps, so that they start with the same path prefix. Helps grouping all your sources in the same node in the source tree, when using the debugger in the browser developer tools.

Synopsis

import { createPathTransform } from 'rollup-sourcemap-path-transform'

export default {
  input: 'src/index.js',
  output: {
    file: 'dist/index.js',
    sourcemap: true,
    // Rebase all source map sources to /compi
    sourcemapPathTransform: createPathTransform({
      prefixes: {
        '*src/components/': '/compi/comps/',
        '/node_modules/': '/compi/deps/'
      }
    })
  }
}

Installation

Make sure that you use Node.js 14 or newer and Rollup 2 or newer. Use your favourite package manager - NPM, PNPM or Yarn:

npm i -D rollup-sourcemap-path-transform
pnpm i -D rollup-sourcemap-path-transform
yarn add -D rollup-sourcemap-path-transform

Usage

Edit a rollup.config.js configuration file, import the createPathTransform function, call it to create a transformation method and assign it to the sourcemapPathTransform property of the output configuration:

import { createPathTransform } from 'rollup-sourcemap-path-transform'

const sourcemapPathTransform = createPathTransform({
  prefixes: {
    '*src/': '/myproj/'
  }
})

export default {
  input: 'src/index.js',
  output: {
    file: 'dist/index.js',
    sourcemap: true,
    sourcemapPathTransform
  }
}

Then call rollup either via the command-line or programmatically.

Options

The following options can be passed in an object to the createPathTransform function.

prefixes

Type: Object
Default: {}

Map of path prefixes to path replacements. The prefixes will be searched in the declared order and as soon as the first will match the beginning of the source path, it will be replaced with the value in the map tuple. If a prefix start with an asterisk (*) it will be search anywhere in the source path.

requirePrefix

Type: Boolean
Default: false

If enabled and no prefix is detected in a source path, the transformation will fail by throwing an error.

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Lint and test your code.

License

Copyright (C) 2022 Ferdinand Prantl

Licensed under the MIT License.

rollup-sourcemap-path-transform's People

Contributors

prantlf avatar semantic-release-bot avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.