In angular-cli, how does the “lazy” attribute work to load global libraries?

后端 未结 2 1245
后悔当初
后悔当初 2021-01-06 05:38

By adding them to the scripts property of .angular-cli file, one can load global scripts into your app. This example comes from the documentation:

\         


        
2条回答
  •  抹茶落季
    2021-01-06 06:02

    If you configure the "lazy" attribute in the .angular-cli.json to load global libraries, you need to "lazy load" the script when needed. Here is the steps to setup.

    1.Configure .angular-cli.json in the apps[0].scripts array.

    "scripts": [
        { "input": "../node_modules/jquery/dist/jquery.js", "output": "jquery", "lazy": true }
    ],
    

    You'll get an jquery.bundle.js file in the build output.

    2.Load the generated script by appending

提交回复
热议问题