javascript - 无法在本地使用使用 webpack 创建的包
问题描述
我已经使用 webpack 创建了 demo_package,但无法在另一个包中使用以下是 demo_package 的 src/index.js、package.json 和 webpack.config.js 文件
src/index.js
function hello(){
console.log("hellow world")
}
export default hello;
演示/包/package.json
{
"name": "demo_pack",
"version": "1.0.0",
"description": "",
"main": "dist/main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack"
},
"author": "",
"license": "ISC",
"dependencies": {
"webpack": "^4.41.2"
},
"devDependencies": {
"webpack-cli": "^3.3.10"
}
}
演示/webpack.config.js
const path = require('path');
module.exports = {
entry: './src/index.js',
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist'),
},
};
以下是我在测试中使用它的方式
var hello =require('demo_pack');
hello();
错误是你好不是一个函数,我已经在本地链接了我的包,在此先感谢
解决方案
更新您的webpack.config.js
.
const path = require('path');
module.exports = {
entry: './src/index.js',
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist'),
publicPath: "",
library:"Hello",
libraryTarget:"umd",
globalObject: "this"
},
};
推荐阅读
- python - 将 json 对象中的特定名称-值对顺序附加到 csv 文件
- rcpp - R::runif() 和 Rcpp::runif() 之间的区别
- python - 如何通过使用 itemgetter 的列表值对字典进行排序?
- python - 如何从我的列表和python中的元组中删除空白引号?
- xamarin - Azure Devops 构建失败:未找到具有提供的指纹的证书
- javascript - 我如何在不和谐 v12 中列出角色中的所有成员?
- python - cadytsiterate.py 的输入是什么?
- dataframe - 如何过滤朱莉娅数据框?
- kotlin - 如何找到默认的 kotlin 编译器参数值?
- r - R语言定义:使用美元符号索引命名向量