私は反応を覚えようとしており、既存のプロジェクトにも導入しようとしています。したがって、私はどこでもそれを使用するのではなく、理にかなったいくつかの場所で反応を使用したいと考えています。reactをアプリケーションではなくコンポーネントライブラリとして使用する方法
問題は、私の頭を包むことができないエントリーポイントの概念です。私が持っていることを好むだろう:私のcshtml
内部
ReactDOM.render(
<MyComponent/>,
document.getElementById("componentExample")
);
<div id='componentExample'></div>
近くではなく、別のjsx
インチ私はcshtml
でjsx
構文を使用することができないことを理解し、私は
<script src="@Url.Content("~/Scripts/dist/bundle.js")"></script>
<script>
ReactDOM.render(
React.createElement(MyComponent, {}, null), document.getElementById("componentExample")
);
</script>
を書く場合MyComponent
が定義されていないので、これは実際に動作しません。それは私のbundle.js
(私はエントリーポイントとしてそれを追加しなければならなかった)に含まれていますが、それはいくつかのwebpack
の範囲内にあり、さらされていません。
これを行う正しい方法は何ですか?
私の目標は、アプリケーションに適したコンポーネントをいくつか書いて、リアクションベースのアーキテクチャに完全に移行することなく、ここやそこで使うことです。
私のセットアップは、webpack
+ babel polyfill
+ typescript
+ react
であり、これはASP.NET MVC
です。
マイwebpack.config.js
は次のとおりです。
var config = {
entry: ['babel-polyfill', "./SiteScripts/React/index.tsx", "./SiteScripts/React/Components/MyComponent.tsx"],
output: {
filename: "./Scripts/dist/bundle.js",
},
// Enable sourcemaps for debugging webpack's output.
devtool: "source-map",
resolve: {
// Add '.ts' and '.tsx' as resolvable extensions.
extensions: [".webpack.js", ".web.js", ".ts", ".tsx", ".js"]
},
module: {
rules: [
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
{
enforce: 'pre',
test: /\.js$/,
loader: "source-map-loader"
},
// All files with a '.ts' or '.tsx' extension will be handled by 'ts-loader'.
{
test: /\.tsx?$/, loaders: ['babel-loader', "ts-loader"], exclude: /node_modules/
}
]
},
plugins : []
}
if (process.env.NODE_ENV === "production") {
config.devtool = "cheap-module-source-map";
}
module.exports = config;
また、これは(建築についての質問など)の質問に多少関連している:私は私のbundle.js
を小さくしたいのですが - それは今30Kの線です。それはおそらく私が間違った方法でreact
を使用しようとしているからでしょうか?