Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

请问 webpack import 的顺序与流程是如何的?我如何知道我要打包的是哪个位置的js文件?

前端的技术环境是 angular10 + angular CLI

我在js文件中很正常的 import 了一个 NPM 包。

import { DA_SERVICE_TOKEN} from '@delon/auth';

这个NPM包的目录结构如下:

image.png

然后我通过浏览器的源码查看了 webpack 的打包结果:

image.png

可以很明显的看到 webpack 给我打的 node_modules/@delon/auth/__ivy_ngcc__/fesm2015 目录下的 auth.js 文件,因此我就产生了几点疑问:

  1. 为什么打包的是这个目录下的js文件?为什么不是bundles、esm2015、fesm2015等目录下的js文件?它的判定依据是什么?
  2. 为什么我在编辑器中按住 Ctrl 键点击 DA_SERVICE_TOKEN 这个方法,IDE会给我跳转到对应的 TS 的类型定义文件上去?而不是对应的方法本体呢?
  3. 请问fesm/esm/bundles 它们之间的区别是什么?这些标准是谁规定的?我查了下好像 fesm 是 flat esm 的意思。

这些疑问困惑我好久了,请各位大佬指点下我,感觉总是想不明白,感觉很痛苦。

然后我也猜测是 package.json 中有配置,但是我全局搜了下,发现有多处与 __ivy_ngcc__/fesm2015 相关的配置定义,我查了下貌似都没有相关记录,这里我也把 package.json 的内容也发下吧。

{
  "_from": "@delon/auth@^10.0.0-beta.4",
  "_id": "@delon/[email protected]",
  "_inBundle": false,
  "_integrity": "sha1-y1f+c4Ci1cTT4AxfdO4J0wYSPe8=",
  "_location": "/@delon/auth",
  "_phantomChildren": {},
  "_requested": {
    "type": "range",
    "registry": true,
    "raw": "@delon/auth@^10.0.0-beta.4",
    "name": "@delon/auth",
    "escapedName": "@delon%2fauth",
    "scope": "@delon",
    "rawSpec": "^10.0.0-beta.4",
    "saveSpec": null,
    "fetchSpec": "^10.0.0-beta.4"
 },
  "_requiredBy": [
    "/"
 ],
  "_resolved": "https://registry.npm.taobao.org/@delon/auth/download/@delon/auth-10.0.0-beta.5.tgz",
  "_shasum": "cb57fe7380a2d5c4d3e00c5f74ee09d306123def",
  "_spec": "@delon/auth@^10.0.0-beta.4",
  "_where": "/Users/shenguotao/Documents/taptap/ng-alain",
  "author": {
    "name": "cipchk",
    "email": "[email protected]"
 },
  "bugs": {
    "url": "https://github.com/ng-alain/ng-alain/issues"
 },
  "bundleDependencies": false,
  "dependencies": {
    "@delon/util": "^10.0.0-beta.5",
    "tslib": "^2.0.0"
 },
  "deprecated": false,
  "description": "Simple user authentication, support Json Web Token & Simple Token.",
  "es2015_ivy_ngcc": "__ivy_ngcc__/fesm2015/auth.js",
  "es2015": "fesm2015/auth.js",
  "esm2015": "esm2015/auth.js",
  "fesm2015_ivy_ngcc": "__ivy_ngcc__/fesm2015/auth.js",
  "fesm2015": "fesm2015/auth.js",
  "homepage": "https://ng-alain.com",
  "keywords": [
    "angular auth",
    "ng auth",
    "ngx auth",
    "angular jwt",
    "ng jwt",
    "ngx jwt",
    "delon",
    "ng-alain",
    "alain",
    "antd",
    "ng-zorro-antd"
 ],
  "license": "MIT",
  "main": "bundles/auth.umd.js",
  "metadata": "auth.metadata.json",
  "module_ivy_ngcc": "__ivy_ngcc__/fesm2015/auth.js",
  "module": "fesm2015/auth.js",
  "name": "@delon/auth",
  "repository": {
    "type": "git",
    "url": "git+https://github.com/ng-alain/delon.git"
 },
  "sideEffects": false,
  "typings": "auth.d.ts",
  "version": "10.0.0-beta.5",
  "__processed_by_ivy_ngcc__": {
    "es2015": "10.1.1",
    "fesm2015": "10.1.1",
    "module": "10.1.1",
    "typings": "10.1.1"
 },
  "scripts": {
    "prepublishOnly": "node --eval "console.error('ERROR: Trying to publish a package that has been compiled by NGCC. This is not allowed.nPlease delete and rebuild the package, without compiling with NGCC, before attempting to publish.nNote that NGCC may have been run by importing this package into another project that is being built with Ivy enabled.n')" && exit 1" }
}

最后:跪求大佬解惑~~!!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...