简体   繁体   English

如何使 p5 中的滑块与 webpack 一起使用?

[英]How to make slider from p5 work with webpack?

I am using p5.js library with webpack and it works just fine.我在 webpack 中使用 p5.js 库,它工作得很好。 However when I try to import createSlider from p5.dom it fails但是,当我尝试从 p5.dom 导入createSlider时它失败了

import p5 from "./p5";
import * as dom from './addons/p5.dom'
import {createSlider} from './addons/p5.dom'


const s = (p) => {
    p.setup = function () {
        p.createCanvas(200,200);
        slider = createSlider(0, 360, 60, 40);
        slider.position(10, 10);
        slider.style('width', '80px');
    };

};

let myp5 = new p5(s, 'p5cont');

I tried with dom.createSlider() with no success.我尝试使用dom.createSlider()没有成功。 In both cases the console reports createSlider is not a function .在这两种情况下,控制台报告createSlider is not a function What's wrong?怎么了?

As of the latest p5.js (v1.1.9 at the time of writing), p5.dom is a part of the main p5.js library.对于最新的 p5.js(在撰写本文时为 v1.1.9),p5.dom 是主要 p5.js 库的一部分。 In other words, you don't need to import p5.dom separately to use createSlider() .换句话说,您不需要单独导入 p5.dom 来使用createSlider()

The following code makes p5's slider work with webpack.下面的代码使 p5 的滑块与 webpack 一起工作。

import p5 from "./p5.min.js"

let sketch = function(p){
    p.setup=function(){
        p.createCanvas(500,500)
        p.background('blue')
        p.createSlider(0,100)
    }
}

let myp5 = new p5(sketch)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM