reactjs - 'npm pack' React Component to use in other projects -
tl;dr
after re-reading post, may reducible "how can compile jsx -> js before packing package". seeing unexpected token error on same line jsx begins.
goal
i have react component wrote renders waveform visualizer using canvas tag. drawing in component , relies on nothing other react.
the host project
the component want package 'waveformvisualizer
living in project created within. project has typical structure such index.js
entry point webpack, babel loaders allowing me write component using es6 , jsx among es7 features ...
syntax object spreading. in projectdir/src/components
there <app />
component renders <waveformvisualizer />
component in center of page. dist
folder hold generated bundle.js
, etc..
exporting package locally
i'm trying "publish" locally @ moment. though may publish npm's registry soon, right want able run npm install ../projects/waveformvisualizer/waveformvisualizer-1.0.0.tgz
, import waveformvisualizer './waveformvisualizer
wherever want render component in separate projects. seems npm pack
partial part of full publishing pipeline let me @ least import package on machine. set package.json
file in package containing project. set name , version, , main
field point file react component. run npm pack
. places waveformvisualizer-1.0.0.tgz
in project root directory.
the problem
so want use component in brand new project. cd new project , run npm install ../projects/waveformvisualizer/waveformvisualizer-1.0.0.tgz
. seems add lot of stuff node_modules/waveformvisualizer
. (it seems need npm ignore of unimportant files). nevertheless, waveformvisualizer.js
component file there. when run import waveformvisualizer 'waveformvisualizer
, hit save, webpack-dev-server recompiles , see following:
error in ./node_modules/waveformvisualizer/src/components/waveformvisualizer.js module parse failed: /users/<me>/projects/testnpmproject/node_modules/waveformvisualizer/src/components/waveformvisualizer.js unexpected token (165:3) may need appropriate loader handle file type. | render() { | return ( | <div> | <canvas | ref={canvasref => (this.canvasref = canvasref)} @ ./src/index.js 5:26-55 @ multi (webpack)-dev-server/client?http://localhost:8080 ./src/index.js
i've tried searching around error haven't found helpful far. 1 know can fix situation?
Comments
Post a Comment