Coder Social home page Coder Social logo

perrin4869 / karma-node-resolve-preprocessor Goto Github PK

View Code? Open in Web Editor NEW

This project forked from brion-fuller/karma-node-resolve-preprocessor

0.0 1.0 0.0 152 KB

Karma preprocessor to resolve bare module imports to `node_modules` folder

JavaScript 100.00%

karma-node-resolve-preprocessor's Introduction

karma-node-resolve-preprocessor

Karma preprocessor to host bare module imports using the Node resolution algorithm, for using third party modules in node_modules.

The problem

Starting version 3.1.0 Karma can natively run ESModule imports using type=module flag. Browsers module has a limitation of not being able to handle bare module imports (i.e. import {LitElement} from 'lit-element';). This will cause an error requiring a full url or a relative path. One solution is using a npm assist service like unpkg but this has the limitation of online only.

This preprocessor aims to help test esmodules without the need to compile or bundle your code.This tool can be used to rewrite bare module imports to a fully qualified path hosted by karma.

Installation

npm install karma-node-resolve-preprocessor --save-dev

Configuration

In order for this preprocessor to work, it is required to include the node_modules in files and preprocessors field:

// karma.conf.js
module.exports = (config) => {
  config.set({
    files: [
      { type: "module", pattern: "test/**/*.js" },
      { type: "module", pattern: "src/**/*.js", included: false },
      {
        type: "module",
        pattern: "node_modules/@(lit-element|lit-html)/**/*.js",
        included: false,
      },
    ],
    preprocessors: {
      "@(src|test)/**/*.js": ["node-resolve"],
      "node_modules/@(lit-element|lit-html)/**/*.js": ["node-resolve"],
    },
  });
};

Example:

// Given
import { LitElement, html } from "lit-element";

// Rewrites to
import {
  LitElement,
  html,
} from "/base/node_modules/lit-element/lit-element.js";

karma-node-resolve-preprocessor's People

Contributors

brion-fuller avatar dependabot[bot] avatar

Watchers

 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.