我正在创建一个npm包,并使用像babel,eslint等加载器的webpack。然而,我假设最终编译版本的包应该只包含一个模块,不包含webpackBootstrap。
我现在的package, webpack config and source。我把它剥离出来只是为了让它“工作”。
我采取的步骤是检查它是否正常工作:
npm install
npm run build
npm install -g .
node
var test = require('test-package');
导致此错误:
Error: Cannot find module 'test-package'
at Function.Module._resolveFilename (module.js:337:15)
at Function.Module._load (module.js:287:25)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at repl:1:12
at REPLServer.defaultEval (repl.js:248:27)
at bound (domain.js:280:14)
at REPLServer.runBound [as eval] (domain.js:293:12)
at REPLServer.<anonymous> (repl.js:412:12)
at emitOne (events.js:82:20)
我是新来的webpack和npm,如果你需要更多的信息,请告诉我。
发布于 2016-02-02 02:16:52
将output.libraryTarget设置为umd
。这样你就可以从不同的模块系统(global,AMD,CommonJS)轻松使用。
output.library是另一个需要设置的有用字段。它应该与您想要的库全局名称相匹配。
除此之外,还有另一个问题。要使导入正常工作,需要使用npm link
。此功能在开发过程中非常有用。您可以通过npm unlink
恢复链接。
https://stackoverflow.com/questions/35131367
复制相似问题