Giter VIP home page Giter VIP logo

Comments (5)

matthewoates avatar matthewoates commented on May 23, 2024 8

Modules should be separated, and those individual modules should require only what they depend on. I'm doing some preliminary testing with this library and if it works well with my codebase I can take a stab at this.

from react-konva.

bini1988 avatar bini1988 commented on May 23, 2024 4

To solve this I created the file custom-konva.js with content:

/**
 * In webpack config should be defined:
 *  alias: {
 *    "konva": path.resolve(ROOT, "./custom-konva.js"),
 *  },
 */
var Konva = require("./node_modules/konva/src/Core");

require("./node_modules/konva/src/Animation");
require("./node_modules/konva/src/Tween");
require("./node_modules/konva/src/DragAndDrop");

require("./node_modules/konva/src/shapes/Circle");
require("./node_modules/konva/src/shapes/Line");
require("./node_modules/konva/src/shapes/Path");
require("./node_modules/konva/src/shapes/Rect");
require("./node_modules/konva/src/shapes/Text");

module.exports = Konva;

from react-konva.

lavrton avatar lavrton commented on May 23, 2024 3

Just implemented minimal version bundle, so it should work without extra config from bundlers. It is available with [email protected].

// load minimal version of 'react-konva`
import { Stage, Layer, Rect } from "react-konva/lib/ReactKonvaCore";

// minimal version has to support for core shapes and filters
// if you want import a shape into Konva namespace you can just do this:
import "konva/lib/shapes/Rect";

Demo: https://codesandbox.io/s/6l97wny44z

More info: https://github.com/konvajs/react-konva#minimal-bundle

Have a question? Ask here.

from react-konva.

lavrton avatar lavrton commented on May 23, 2024

I think it should be possible to do this manually.

  1. Define alias in webpack conf:
{
    // ...
    resolve: {
        alias: {
            'konva': './src/my-konva-version.js'
        }
    }
    // ...
}
  1. Make ./src/my-konva-version.js and require insede it only necessary modules:
import Konva from 'konva/src/Core';
// now you have Konva object with Stage, Layer, FastLayer, Group, Shape and some additional utils function
// so there are no shapes (rect, circle, etc), no filters, no d&d support.


// but you can simply add anything you need:
import 'konva/src/shapes/rect';
//now Konva.Rect is available to use

I didn't test that. But in theory, should work. It will be nice to have a better way. Any ideas are welcome.

from react-konva.

ajGingrich avatar ajGingrich commented on May 23, 2024

is there anyway to do this with rollup? It looks the rollup-plugin-alias doesn't currently support aliases node modules. This pull request is still open from june 18th

rollup/rollup-plugin-alias#45

from react-konva.

Related Issues (20)

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.