Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import live2dcubismcore.min.js in javascript? #39

Closed
thisismygatekeeper opened this issue Dec 21, 2021 · 2 comments
Closed

import live2dcubismcore.min.js in javascript? #39

thisismygatekeeper opened this issue Dec 21, 2021 · 2 comments

Comments

@thisismygatekeeper
Copy link

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
Copy link
Owner

guansss commented Dec 21, 2021

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants