我試圖去抓住用打字稿2的WebPack和角1.5,但建設時的WebPack不斷抱怨它:說服的WebPack使用node_modules/@類型
無法解析模塊「@類型/角'in C:\ play \ gt \ src
我很難過。一直在谷歌搜索和搞亂,但我無處可去。
我app.ts樣子:
import * as angular from "@types/angular";
let app = angular.module ("GT.module", []);
我tsconfig樣子:
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"sourceMap": true,
"typeRoots" : [
"node_modules/@types"
]
},
"exclude": [
"node_modules",
"**/*.spec.ts"
],
"include" : [
"src/**/*"
]
}
...,最後的WebPack配置:
module.exports = {
entry: './src/app.ts',
output: {
filename: './dist/app.js'
},
devtool: "source-map",
resolve: {
extensions: ['', '.webpack.js', '.web.js', '.ts', '.js'],
modulesDirectories: ["node_modules"]
},
module: {
loaders: [
{ test: /\.ts$/, loader: 'ts-loader' }
]
}
}
謝謝!這已經解決了它。 Typescript目標帖子似乎在不停地移動,很難找到最新的文章。 – jeffeld
是啊,我知道,JavaScript生態系統發展得非常快,嘗試官方文檔,它保持相當不錯。例如,這個鏈接將使用typescript包裝webpack:https://www.typescriptlang.org/docs/handbook/react-&-webpack.html –