guansss / pixi-live2d-display

A PixiJS plugin to display Live2D models of any kind.
https://guansss.github.io/pixi-live2d-display/
MIT License
870 stars 132 forks source link

import live2dcubismcore.min.js in javascript? #39

Closed thisismygatekeeper closed 2 years ago

thisismygatekeeper commented 2 years ago

I'm trying to use this library in chrome extension. The content script doesn't have html context (thus no <script> tag). We have successfully imported live2d.min.js and it worked for the cubism v2. But we couldn't import live2dcubismcore.min.js. Have tried to use

import * as Live2DCubismCore from 'live2dcubismcore.min.js';
window.Live2DCubismCore = Live2DCubismCore;

but got an error Failed to start up Cubism 4 framework.. Strangely, there's also no retry logs being printed.

Any thoughts how we can properly include this library? Thanks!

guansss commented 2 years ago

Similiar to #19, live2dcubismcore.min.js is not a module, nor does it mount anything on global scope (usually window), that's why it's supposed to be loaded by <script>.

Not familiar with chrome extension, but I guess there's a way to load this script separately, so that it'll work as if it's loaded by <script>.

If that doesn't work, another way is to modify the script by replacing the first statement:

var Live2DCubismCore;

with:

window.Live2DCubismCore = {};

then the variable will be correctly exposed, and the script can be imported as usual:

import 'live2dcubismcore.min.js';
thisismygatekeeper commented 2 years ago

OMFG it worked!!!! @guansss LOVE YOU MY BRO!!