reactjs - Webpack + React + Typescript -
is possible use webpack react , typescript , able bundle web bundle, still able debug original typescript , react code? in webpack i'm using ts-loader , ts-jsx-loader plus devtool: "source-map", when try browser debugging, can't see original ts code instead see code has been changed webpack.
my current basic webpack.config.js file:
var webpack = require('webpack'); module.exports = { entry: ['./app/main.ts'], output: { path: './build', filename: 'bundle.js' }, debug: true, devtool: 'source-map', plugins: [ new webpack.optimize.dedupeplugin(), new webpack.optimize.uglifyjsplugin() ], resolve: { extensions: ['', '.ts', '.js'] }, module: { loaders: [ { test: /\.ts$/, loader: 'ts-loader!ts-jsx-loader' } ] } }; tsconfig.json:
{ "compileonsave": false, "version": "1.5.0-alpha", "compileroptions": { "target": "es5", "module": "commonjs", "nolib": false, "sourcemap": true, "noimplicitany": true, "removecomments": true }, "files": [ "./appcomponent.ts", "./libs/jsx.d.ts", "./libs/react.d.ts", "./libs/webpack-runtime.d.ts", "./main.ts" ] } for example - oryginal .ts file looks like:
import react = require('react'); class appcomponent extends react.component<any, any> { render () { return react.jsx(` <h1>he world!</h1> `); } }; export = appcomponent; and in chrome debugger looks this:
var __extends = this.__extends || function (d, b) { (var p in b) if (b.hasownproperty(p)) d[p] = b[p]; function __() { this.constructor = d; } __.prototype = b.prototype; d.prototype = new __(); }; var react = __webpack_require__(2); var appcomponent = (function (_super) { __extends(appcomponent, _super); function appcomponent() { _super.apply(this, arguments); } appcomponent.prototype.render = function () { return (react.createelement("h1", null, "he world!")); }; return appcomponent; })(react.component); ; module.exports = appcomponent; /***************** ** webpack footer ** ./app/appcomponent.ts ** module id = 158 ** module chunks = 0 **/
you don't need use ts-jsx-loader.
in tsconfig.json file need this:
{ "compileroptions": { "jsx": "react", "sourcemap": true, // ... other options } } and of course, still need devtool option in webpack config file
Comments
Post a Comment