【发布时间】:2016-01-20 10:41:11
【问题描述】:
我正在尝试创建一个非常痛苦的 NPM 模块:react-smallgrid
import React from 'react';
import _ from 'lodash';
export default class SmallGrid extends React.Component{
编译:
browserify: {
options: {
transform: [
['babelify', {
presets: ['react', 'es2015']
}]
]
},
jsx: {
files: {
'./dist/js/smallgrid.js': [
'./src/smallgrid.jsx',
]
}
},
当我在另一个项目/jsx 中导入 js 文件并尝试对其进行浏览时,它会给出错误:
错误:无法从“/Users/me/code/react-smallgrid/dist/js”中找到模块“./ReactMount”
我以为它已经编译好使用了?我不明白这个。
同时
我尝试使用 webpack 构建它,它会提供以下输出:
> webpack -p
Hash: 00fd87c95d39230bd485
Version: webpack 1.12.11
Time: 14002ms
Asset Size Chunks Chunk Names
smallgrid.js 248 kB 0 [emitted] smallgrid
+ 160 hidden modules
WARNING in smallgrid.js from UglifyJs
Condition always true [./~/react/lib/ReactMount.js:764,0]
Condition always true [./~/react/lib/findDOMNode.js:46,0]
Condition always true [./~/react/lib/instantiateReactComponent.js:80,0]
还是不行。
【问题讨论】:
-
你的 package.json 是什么样的? React 是否包含在您编译的库中?
-
@HenrikAndersson 是的,作为依赖项 (link)
-
@Tjorriemorrie 你能把消费项目如何尝试粘贴到
importSmallGrid吗? -
@DavidPine
import SmallGrid from 'react-smallgrid';。在webpack branch 上npm run kitchen_sink可能更容易,我正在尝试使用示例文件复制问题 -
@Tjorriemorrie 你所有的例子现在都在工作。请检查答案和我发给你的 PR。
标签: reactjs npm ecmascript-6 browserify