Security News
The Dark Side of Open Source
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
01-custom-library-npm
Advanced tools
```js npm init -y npm i webpack webpack-cli lodash -D ``` #### 2)配置webpack * 将项目中使用lodash也打包进项目中,增大了项目的体积(不推荐) ```js // webpack.config.js const path = require('path')
Readme
npm init -y
npm i webpack webpack-cli lodash -D
// webpack.config.js
const path = require('path')
module.exports = {
mode: 'development',
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
clean: true,
filename: 'webpack-numbers.js',
library: {
// library 向外暴露的对象名
name: 'webpackNumbers',
// 兼容不同的环境 CommonJS、AMD、Node.js 等
type: 'umd',
},
},
}
const path = require('path')
module.exports = {
mode: 'development',
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
clean: true,
filename: 'webpack-numbers.js',
library: {
// library 向外暴露的对象名
name: 'webpackNumbers',
// 兼容不同的环境 CommonJS、AMD、Node.js 等
type: 'umd',
},
},
// 外部扩展:https://webpack.docschina.org/configuration/externals/#externals
externals: {
lodash: {
commonjs: 'lodash',
commonjs2: 'lodash',
amd: 'lodash',
root: '_',
},
},
}
"build": "webpack --config webpack.config.js"
同时将package.json
文件中main
设置为打包构建的文件
"main": "dist/webpack-numbers.js",
taobao,taobao
镜像是只读镜像,会发布失败npm config get registry
// 发布library需要使用官方仓库
npm config set registry https://registry.npmjs.org
npm config set registry https://registry.npm.taobao.org
npm login
输入用户名、密码和邮箱登录npmnpm publish
npm logout //登出
// 如果不知道当前登录的账号可以用who命令查看身份:
npm who am i
// 发布的包在72小时内是可以删除的
npm unpublish <pkg>[@<version>]
npm unpublish 01-custom-library-npm@1.0.1
package.json
中的version
(不能和之前的版本相同)npm publish
更新包registry
设置为官方仓库,否则发布失败package.json
中的版本号// test.js
const webpackNumbers = require('../dist/webpack-numbers')
console.log(webpackNumbers.numToWord(3));
<body>
<script src="../dist/webpack-numbers.js"></script>
<script>
console.log(webpackNumbers);
</script>
</body>
FAQs
```js npm init -y npm i webpack webpack-cli lodash -D ``` #### 2)配置webpack * 将项目中使用lodash也打包进项目中,增大了项目的体积(不推荐) ```js // webpack.config.js const path = require('path')
The npm package 01-custom-library-npm receives a total of 97 weekly downloads. As such, 01-custom-library-npm popularity was classified as not popular.
We found that 01-custom-library-npm demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
Research
Security News
The Socket Research team found this npm package includes code for collecting sensitive developer information, including your operating system username, Git username, and Git email.
Security News
OpenJS is warning of social engineering takeovers targeting open source projects after receiving a credible attempt on the foundation.