Angular 6 CLI -> how to make ng build build project + libraries

前端 未结 9 536
感情败类
感情败类 2020-12-31 01:58

So the question is pretty basic but I can\'t find it.

I created a new app through ng new my-project, followed by a ng g library my-library.

9条回答
  •  鱼传尺愫
    2020-12-31 02:27

    use with simple node js like this:

    create js file in ~App root (e.g: build.js).

    then placed the following codes in your file.

    var child_process = require('child_process');
    
    console.log("building all packages...\n");
    
    var files = GetProjectList();
    var count = files.length;
    var counter = 1;
    
    files.forEach(item => 
    {
        try 
        {
            console.log(`${counter++} of ${count} building ${item.fileName}...`);
            child_process.execSync(`ng b ${item.fileName}`);
            console.log(`${item.fileName} built successfully.\n`);
        } 
        catch (er) 
        {
            console.error(` Couldn't build ${item.fileName} .\n`);
        }
    });
    
    
    
    function GetProjectList()
    {
        // enter list of projects here.
        var lst = [];
        lst.push({ fileName : 'project1' });
        lst.push({ fileName : 'project2' });
        lst.push({ fileName : 'project3' });
        //...
        return lst;
    }
    

    Finally, run your file with node js command. like this:

    node build.js             // `build.js` is name of your created file on above
    

    pay attention to the unicode your file. // build.js

    it's working well.

    I hope is useful.

提交回复
热议问题