我试图通过awesome- typescript -loader使 webpack、typescript 和 react.js 协同工作,但我经常遇到错误。
我在版本 0.3.0-rc.2 和 webpack 1.8.9 上使用了很棒的typescript加载器
这是我的 webpack.config.js:
module.exports = {
entry: './ui/index.ts',
output: {
path: __dirname + '/build-ui',
filename: 'app.js',
publicPath: 'http://localhost:8090/assets'
},
module: {
loaders: [
{
test: /\.jsx$/,
loader: 'jsx-loader?insertPragma=React.DOM&harmony'
},
{
test: /\.css$/,
loader: "style-loader!css-loader"
},
{
test: /\.scss$/,
loader: "style-loader!css-loader!sass-loader"
},
{
test: /\.(png|jpg)$/,
loader: 'url-loader?limit=8192'
},
{
test: /\.ts$/,
loader: 'awesome-typescript-loader'
}
]
},
resolve: {
extensions: ['', '.js', '.jsx', '.ts']
}
};
当我运行 webpack 开发服务器时,我的 index.ts 如下所示:
alert('hello');
它指出以下错误:
ERROR in ./ui/index.ts
/Users/..../typings/node/node.d.ts:29:12
Subsequent variable declarations must have the same type. Variable 'require' must be of type 'WebpackRequire', but here has type '{ (id: string): any; resolve(id: string): string; cache: any; extensions: any; main: any; }'.
当我放入参考路径时也是如此。
当我尝试通过import React = require('react');
它导入 React.js时:
ERROR in ./ui/index.ts
Module build failed: Cannot resolve module 'child_process' in /..../typings/node
Required in /..../typings/node/node.d.ts
我从加载程序存储库中复制了 node.d.ts 文件,但仍然没有运气。
有没有人能够顺利地使这种组合工作?或者我应该使用不同的 Web 打包程序?我真的很想让它与 webpack 一起使用。