What’s behind the NPM run script

Time:2022-5-11

npm run build:mylib

What's behind the NPM run script

The target build: mylib executed by NPM run is defined in package JSON:

What's behind the NPM run script

The actual command is: yarn — CWD feature LIBS / my lib & & NG build my lib — configuration production

What's behind the NPM run script

Ng build: compile the angular application into the output directory named dist / under the given output path. This command must be executed in the workspace directory.

When used to build a library, other builders are called and only TS config, configuration, and watch options are applied.

When you create a project using the CLI, the “production” configuration is created by default and can be used by specifying the — configuration = “production” or — prod option.

If you encounter an error message:

[error] Error: Unable to write a reference to UrlPipe in C:/Code/SPA/mySPA/spartacus/projects/core/src/routing/configurable-routes/url-translation/url.pipe.ts from C:/Code/SPA/mySPA/spartacus/projects/core/src/routing/configurable-routes/url-translation/url.module.ts

at ReferenceEmitter.emit (C:\Code\SPA\mySPA\spartacus\node_modules\@angular\compiler-cli\src\ngtsc\imports\src\emitter.js:85:19)

Why my lib and the URL under the core folder pipe. Are they related?

What's behind the NPM run script

Create an empty test lib, and then ng build it to see if there are the same errors.

What's behind the NPM run script

What's behind the NPM run script

No problem.
What's behind the NPM run script

I found that as long as I import Icon_ After type, this error will appear:

What's behind the NPM run script

When I comment out the code in line 2 above, the build error disappears:

What's behind the NPM run script

Check ng package. Of Spartacus and other libraries JSON file, whose lib area has a reference to @ Spartacus / storefront:

What's behind the NPM run script

Add Icon to the new test lib service_ Reference to type:

What's behind the NPM run script

There was also an immediate error:

What's behind the NPM run script

After research, it is found that under the angular library project folder, tsconfig lib. JSON file, add references to @ Spartacus / core and @ Spartacus / storefront to solve the problem:

What's behind the NPM run script

Successfully build through:

What's behind the NPM run script

Many JavaScript libraries, such as jQuery, jasmine test library and angular, will extend the JavaScript environment through new features and syntax. The typescript compiler does not recognize them natively. When the compiler does not recognize it, it throws an error.

You can use typescript type definition file – d. TS file — to tell the compiler the type definition of the library you want to load.
Typescript sensitive editors use these definition files to display the type definitions of various properties in these libraries.
Many libraries include their type definition files in their NPM packages, which can be found by typescript compilers and editors. The same is true of the angular library. Node of any angular application_ The modules / @ angular / core / directory contains several d.ts files that describe various parts of angular.

These d.ts files are shown in the following figure:

What's behind the NPM run script

More Jerry’s original articles are: “Wang Zixi”:
What's behind the NPM run script

Recommended Today

Pyflink development environment tool: Zeppelin notebook

As the python language entrance of Flink, pyflink’s Python language is indeed very simple and easy to learn, but the development environment of pyflink is not easy to build. If you are careless, the pyflink environment will be disordered, and it is difficult to find out the reasons. Today, I’d like to introduce a powerful […]