Thursday, September 8, 2022
HomeGame DevelopmentTo exclude js recordsdata from a construct - Cocos Creator

To exclude js recordsdata from a construct – Cocos Creator


Hello, im korean develper.

I made a javascript file based mostly on nodejs for comfort of growth. Additionally it is within the asset folder and can’t be rerouted as a result of private causes.

My drawback is, this js file doesn’t have to be included within the construct, however it tries to be included within the construct and causes an error. Is there a method to exclude the javascript file within the asset folder from the construct?


Hello, you possibly can attempt to wrap up your js code in defines as you wanted


if (!CC_BUILD) {
// your js code right here
}

I don’t wish to modify the code, since there’s no half that calls the js file, I wish to ignore it within the construct.

Then you may modify a construct course of through an editor extension that it’s good to create.

I agree with you, I used to be already engaged on the method

// hooks.ts
import * as fs from 'fs';

operate moveFile(from: string, to: string) {
    console.log('from : ' + from + ', to : ' + to);
    let dirTemp = to.break up('');
    dirTemp.pop();
    let dir = dirTemp.be part of('');
    !fs.existsSync(dir) && fs.mkdirSync(dir);
    fs.copyFileSync(from, to);
    fs.unlinkSync(from);
}

export async operate onBeforeBuild(choices) {
    let pack = choices['packages'] || {};
    let module = pack['build-ignore-files'] || {};
    let listing = (module['ignoreList'] || '').break up(';');
    for (let i = listing.size - 1; i >= 0; i--) {
        listing.push(listing[i] + '.meta');
    }
    for (let path of listing) {
        console.log(path + ' is exist : ' + fs.existsSync(path).toString());
        if (path === '' || !fs.existsSync(path)) {
            proceed;
        }
        moveFile(path, Editor.Undertaking.path + '' + path.break up('').pop());
    }
}

export async operate onAfterBuildAssets(choices) {
    console.log('after_build');
    let pack = choices['packages'] || {};
    let module = pack['build-ignore-files'] || {};
    let listing = (module['ignoreList'] || '').break up(';');
    for (let i = listing.size - 1; i >= 0; i--) {
        listing.push(listing[i] + '.meta');
    }
    for (let path of listing) {
        let tempPath = Editor.Undertaking.path + '' + path.break up('').pop();
        if (tempPath === '' || !fs.existsSync(tempPath)) {
            proceed;
        }
        moveFile(tempPath, path);
    }
}

export operate load() {
    console.log('build-ignore-files load');
}

export operate unload() {
    console.log('build-ignore-files unload');
}

That is my code.

Additionally, in the event you proceed with the construct, the file can be deleted

Nevertheless, there appears to be an issue with asset db. The file has been erased, however it’s nonetheless about to be included within the construct

What ought to i do?

appears it’s good to refresh/replace belongings db, most likely is best delete file through assets-db API immediately as a substitute of FileSystem API.

I additionally thought of that, however I’m utilizing Cocos model 3.6 and I don’t have Editor.assetdb in 3.6 How can I take advantage of the assetdb?

there’s new Message system may show you how to i suppose.

https://docs.cocos.com/creator/guide/en/editor/extension/bundle.html

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments