2017-10-16 61 views
0

我嘗試導入AngularJS 1.6.5到我的應用程序。 我使用webpack 3.7.1作爲模塊打包器。 此外,我使用typescript爲我的代碼transpile。嘗試導入到webpack軟件包時未定義Angularjs

的package.json:

{ 
    "name": "webpack_test_app", 
    "version": "1.0.0", 
    "description": "", 
    "main": "app.js", 
    "scripts": { 
    "test": "echo \"Error: no test specified\" && exit 1" 
    }, 
    "author": "", 
    "license": "ISC", 
    "devDependencies": { 
    "ts-loader": "^2.3.7", 
    "webpack": "^3.7.1" 
    }, 
    "dependencies": { 
    "angular-ui-bootstrap": "^2.5.0", 
    "angular": "1.6.5" 
    } 
} 

webpack.config.js:

module.exports = { 
    entry: './app.js', 
    output: { 
     filename: './views/resources/js/bundle.js' 
    }, 
    resolve: { 
     extensions: ['.ts', '.tsx', '.js'] 
    } 
}; 

app.ts

import angular from './node_modules/angular/angular.js'; 

console.log('angular is -> ', angular); 

所有Chrome控制檯打印後angular is -> undefined

而且我試過import angular from './node_modules/angular/angular';

回答

0

我試圖包括所有的依賴關係。

import * as angular from 'angular'; 
1

安裝分型

做 第一步:執行命令來安裝TSD

npm install -g tsd 

第三步:執行命令來安裝分型

tsd install angular 
tsd install angular-route 

然後app.ts

import angular from 'angular'; 
+0

如果您需要更多信息 https://github.com/toddmotto/angularjs-styleguide/tree/master/typescript –