新しいAngular2プロジェクトでファイルをインポートしようとしています。ファイル拡張子なしでTSファイルをインポートすることができる一方Typescriptは拡張子のないファイルをインポートできません
import { AppModule } from './module/app.module';
「app.module.ts」とされない: エントリファイル「main.ts」が使用している他のtypescriptファイルをインポートすることが可能です。
import { AppComponent } from '../component/app.component';
私はすべてが期待どおりに動作するファイル名に「.TS」を追加した場合...
は私のミスは何ですか?私はノード6.9.4、NPM 4.2.0、2.3.2 typescriptです、角度4.1.0および2.5.1のWebPACKは
私のTSconfigをインストールして、角度ガイド(https://angular.io/docs/ts/latest/guide/webpack.html)
あたりのように私は私がすべてをやっていると仮定します自動的にファイルのトンを検出します.json
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
}
}
マイwebpack.config.js
(デフォルト古典的な解像度設定での書き込み時)var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var helpers = require('./helpers');
module.exports = {
entry: {
'polyfills': './src/polyfills.ts',
'vendor': './src/vendor.ts',
'app': './src/main.ts'
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx']
},
module: {
rules: [
{
test: /\.ts$/,
loader: 'awesome-typescript-loader'
},
{
test: /\.(html|htm|php)$/,
loader: 'html-loader'
},
{
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
loader: 'file-loader?name=assets/[name].[hash].[ext]'
},
{
test: /\.css$/,
exclude: helpers.root('src', 'app'),
loader: ExtractTextPlugin.extract({
fallbackLoader: 'style-loader',
loader: 'css-loader?sourceMap'
})
},
{
test: /\.css$/,
include: helpers.root('src', 'app'),
loader: 'raw-loader'
}
]
},
plugins: [
// Workaround for angular/angular#11580
new webpack.ContextReplacementPlugin(
// The (\\|\/) piece accounts for path separators in *nix and Windows
/angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
helpers.root('./src'), // location of your src
{} // a map of your routes
),
new webpack.optimize.CommonsChunkPlugin({
name: ['app', 'vendor', 'polyfills']
}),
new HtmlWebpackPlugin({
template: '../../template/base/app.php'
})
// new webpack.optimize.UglifyJsPlugin()
],
output: {
filename: '[name].js'
}
};
Typescriptファイルの拡張子は.tsです。最初に.ts拡張子を持つファイルを作成したくないのはなぜですか? –
私のファイルの拡張子が.tsです。拡張子をインポート状態にしないと、ロードされていないという問題があります。 – donnikitos
あなたはtsconfigを共有できますか? –