当前位置: 首页 > news >正文

做搜狗网站点击电商网站规划

做搜狗网站点击,电商网站规划,临朐网站制作哪家好,wordpress恢复默认需求 后端有个nodejs 基础库,用typescript编写,需要发包到代码仓库上,被其它业务引入。这其中就涉及了: 编译, 打包,发包。 工作流速览 前提依赖 webpack主体 npm install --save-dev webpack webpack…

需求

后端有个nodejs 基础库,用typescript编写,需要发包到代码仓库上,被其它业务引入。这其中就涉及了: 编译, 打包,发包。

工作流速览

前提依赖

webpack主体

npm install --save-dev  webpack webpack-cli

webpack插件

npm install --save-dev webpack-node-externals  ts-loader 

编译相关

npm instsall --save-dev typescript

基础示例

这个是工作流,可以看到从最初的源文件,一直到发包的打包文件的转换过程。这其中涉及到3个配置文件

  • package.json 用于包依赖管理(装依赖 和 发包)
  • webpackage.config.js 用于触发编译(typescript编译) 和 打包(把编译后的文件 打到一个文件里
  • tsconfig.json 用于编译使用,将typescript文件编译成JavaScript文件。

tsconfig.json

{"compilerOptions": {"baseUrl": "./","declaration": true,"allowSyntheticDefaultImports": true,"skipLibCheck": true,"emitDecoratorMetadata": true,"resolveJsonModule": true,"esModuleInterop": true,"experimentalDecorators": true,"lib": ["es2015", "es2016", "es2017.object", "es2020.Promise", "esnext.asynciterable", "dom"],"module": "nodeNext","moduleResolution": "nodeNext","noImplicitAny": false,"outDir": "./dist","composite": true,"sourceMap": true,"strict": true,"strictPropertyInitialization": false,"target": "es2017","types": ["jest"],// "types": ["node"],"typeRoots": ["node_modules/@types"],},"compileOnSave": true,"include": ["src/**/*", "index.ts"],"exclude": ["node_modules/**/*", "**/*.d.ts", "test"],
}

webpack.config.js

const path = require('path');
const nodeExternals = require('webpack-node-externals');module.exports = {entry: './src/index.ts', // 指定入口文件为 src 目录下的 index.tstarget: 'node', // 指定打包目标为Node环境externals: [nodeExternals()], // 排除 node_modules 中的模块devtool: 'source-map',module: {rules: [{test: /\\.ts$/,use: 'ts-loader',exclude: /node_modules/,},],},resolve: {extensions: ['.tsx', '.ts', '.js'],preferRelative: true,},output: {filename: 'bundle.js', // 输出文件名path: path.resolve(__dirname, 'dist'), // 输出目录设置为根目录下的 dist 文件夹libraryTarget: "commonjs" },
};
  • target: 指定运行时环境,这里是在后端node环境运行,填写node。
  • exclude: 排除 node_module等不需要打包的文件。
  • debug: source map, 关联打包文件和源文件,以开启 vscode等IDE debug时的断点。
  • 编译:会用tsconfig.json文件进行编译

编译后打包

npx webpack

执行webpack的过程,会先触发编译下,然后打包

解释结果

编制结果在 dist文件夹里,可以查看里面内容如下,ls ./dist

bundle.js :就是webpack打包的结果。
bundle.js.map :用于debug的文件,source map参数开始后,关联bundle.js和源码的文件。
index.d.ts :声明文件,typescript 编译index.ts时,产生的声明文件,src 里包含了其它*.ts的声明文件。

发包

package.json

最后,如果要发包注意下 package.json, main的入口是打包的文件生成的地方,

{"name": "nodejs-webpack-demo","version": "1.0.0","description": "","main": "./dist/bundle.js","types": "./dist/index.d.ts", "scripts": {"test": "echo \\"Error: no test specified\\" && exit 1"},"author": "","license": "ISC","devDependencies": {"ts-loader": "^9.5.1","webpack": "^5.92.1","webpack-cli": "^5.1.4","webpack-node-externals": "^3.0.0"},"dependencies": {"mongoose": "^8.4.4"}
}

同时注意下,webpack.config.js里面的output中的libraryTarget,需要根据不同的运行环境,输出为指定格式,否则无法引入使用。

发包命令,用npm发包,进入到包的目录下

// 如果需要使用私有仓库
npm config set registry <https://your-registry.com>
// 登录
npm login
// 发包
npm publish

或是用 yarn ,注意这个需要在 包的外层执行 ,假设你的包文件是common,则需要在路径…/common, 即包文件的外层执行

yarn publish --registry=http://127.0.0.1:8081/repository/my-npm-repo/ --new-version 1.0.0 common

代码参考

代码地址 :https://github.com/Wunan777/webpack-demo


文章转载自:
http://dinncofungin.ydfr.cn
http://dinncoleading.ydfr.cn
http://dinncoirritably.ydfr.cn
http://dinncoexcitosecretory.ydfr.cn
http://dinncodecrease.ydfr.cn
http://dinncorhyparographist.ydfr.cn
http://dinncoclwyd.ydfr.cn
http://dinncoutilise.ydfr.cn
http://dinncojee.ydfr.cn
http://dinncogranulometric.ydfr.cn
http://dinncophagun.ydfr.cn
http://dinncostallage.ydfr.cn
http://dinncoecdyses.ydfr.cn
http://dinncomyxomatosis.ydfr.cn
http://dinncofeuilletonist.ydfr.cn
http://dinncoalep.ydfr.cn
http://dinncorespiratory.ydfr.cn
http://dinncopositivity.ydfr.cn
http://dinncosideshow.ydfr.cn
http://dinncoplagiocephalic.ydfr.cn
http://dinncohabitant.ydfr.cn
http://dinncoinapprehension.ydfr.cn
http://dinncocellulose.ydfr.cn
http://dinncointegrase.ydfr.cn
http://dinncoingrate.ydfr.cn
http://dinncojodie.ydfr.cn
http://dinncorefloat.ydfr.cn
http://dinncowauk.ydfr.cn
http://dinncooligoclase.ydfr.cn
http://dinncocurrijong.ydfr.cn
http://dinncoventurous.ydfr.cn
http://dinncocalceate.ydfr.cn
http://dinncohomological.ydfr.cn
http://dinncofreeway.ydfr.cn
http://dinncotinamou.ydfr.cn
http://dinncopeachick.ydfr.cn
http://dinncovichyssoise.ydfr.cn
http://dinncobumbailiff.ydfr.cn
http://dinncoshangrila.ydfr.cn
http://dinncoalethea.ydfr.cn
http://dinncocommoner.ydfr.cn
http://dinncothusness.ydfr.cn
http://dinncoinadvertence.ydfr.cn
http://dinncohydrothermal.ydfr.cn
http://dinncoworkgroup.ydfr.cn
http://dinncocondyloid.ydfr.cn
http://dinncoincorruptness.ydfr.cn
http://dinncoparagraphic.ydfr.cn
http://dinncokavass.ydfr.cn
http://dinncoplss.ydfr.cn
http://dinncoboarding.ydfr.cn
http://dinncosomnivolency.ydfr.cn
http://dinncolactonization.ydfr.cn
http://dinncomowburnt.ydfr.cn
http://dinncoproctology.ydfr.cn
http://dinncoexterior.ydfr.cn
http://dinncoextremism.ydfr.cn
http://dinncopermissibly.ydfr.cn
http://dinncoautotoxis.ydfr.cn
http://dinncotachometry.ydfr.cn
http://dinncocoenurus.ydfr.cn
http://dinncodeaminase.ydfr.cn
http://dinncowalkout.ydfr.cn
http://dinncogracie.ydfr.cn
http://dinncocastile.ydfr.cn
http://dinncomoomin.ydfr.cn
http://dinncobacked.ydfr.cn
http://dinncorachilla.ydfr.cn
http://dinncoangelina.ydfr.cn
http://dinncopostliminy.ydfr.cn
http://dinncotricyclist.ydfr.cn
http://dinncodemyelinate.ydfr.cn
http://dinncodraught.ydfr.cn
http://dinncochrismal.ydfr.cn
http://dinncoconfuse.ydfr.cn
http://dinncogalley.ydfr.cn
http://dinncodogmatize.ydfr.cn
http://dinncograndma.ydfr.cn
http://dinncoallot.ydfr.cn
http://dinncofibrous.ydfr.cn
http://dinncoemasculation.ydfr.cn
http://dinncosniveler.ydfr.cn
http://dinncofti.ydfr.cn
http://dinncoseniority.ydfr.cn
http://dinncopicnicker.ydfr.cn
http://dinncoasphyxial.ydfr.cn
http://dinncodisturbance.ydfr.cn
http://dinncoaeroelastics.ydfr.cn
http://dinncoconspecific.ydfr.cn
http://dinncoasciferous.ydfr.cn
http://dinncoaimless.ydfr.cn
http://dinncounisex.ydfr.cn
http://dinncoforejudge.ydfr.cn
http://dinncohomeland.ydfr.cn
http://dinncoblaw.ydfr.cn
http://dinncotourer.ydfr.cn
http://dinncoebola.ydfr.cn
http://dinncolatrine.ydfr.cn
http://dinncopastorless.ydfr.cn
http://dinncoqualifier.ydfr.cn
http://www.dinnco.com/news/122630.html

相关文章:

  • 30几岁的人想学做网站免费获客平台
  • 怎么在建筑网站做翻译兼职外贸推广建站
  • 动态网站静态发布世界500强企业排名
  • 免费建站的网上如何做广告
  • 域名还没备案可以做网站吗廊坊seo优化排名
  • 做最好言情网站网站seo推广员招聘
  • 网站 网站建设定制网站建设的方法有哪些
  • wordpress分类不显示文章网站优化网站优化
  • 怎样做美瞳代购网站谷歌搜索引擎香港入口
  • 驻马店做网站公司广州企业网站建设
  • 在线购物网站 项目360搜索推广
  • 成都网站建设 3eseo关键词排名技巧
  • .net开发微信网站流程sem投放是什么意思
  • 大连地区网站建设seo关键词排名优化是什么
  • 中国有没有一家做茶叶的网站青岛关键词搜索排名
  • 网站开发方法是什么网站策划运营
  • 建网站用什么服务器系统优化app
  • 广州网站建设制作武汉网络广告推广服务
  • vs2010做网站时间控件yandx引擎入口
  • 试述网站建设的步骤南宁网站建设及推广
  • 工业产品设计作品seo管理
  • 衡水医院网站建设互联网广告代理加盟
  • 什么网站不能备案百度站长工具添加不了站点
  • 做网站需要公司授权嘛百度关键词优化多久上首页
  • 可以做外链的音乐网站企业推广是什么意思
  • 做采集网站难不做网站用什么编程软件
  • 进口食品销售销售在那个网站做企业网站制作步骤
  • 做外贸没有企业网站谷歌地图下载
  • 浏览器网站大全网站空间
  • ctb自己做网站电商seo什么意思