我將Angular 1.5應用程序從RquireJS 2.2遷移到Webpack 3.我想設置一個Webpack環境,它將支持當前的RequireJS代碼並逐漸轉換到Webpack + ES6 ,一步一步,編寫測試並重構源代碼。未找到模塊:錯誤:無法解析'exports'
現在,當我嘗試生成由webpack
命令我碰到下面的錯誤捆綁:
[email protected]:~/dev/myapp$ webpack
Hash: 3ac8a9bb3d386514f8a6
Version: webpack 3.4.1
Time: 101ms
Asset Size Chunks Chunk Names
bundle.js 10.7 kB 0 [emitted] main
[0] ./app/bootstrap.js 82 bytes {0} [built]
[2] ./app/app.js 7.37 kB {0} [built]
+ 1 hidden module
ERROR in ./app/app.js
Module not found: Error: Can't resolve 'services/routeResolver' in '/home/trex/dev/myapp/app'
@ ./app/app.js 3:0-175:2
@ ./app/bootstrap.js
ERROR in ./node_modules/angular/index.js
Module not found: Error: Can't resolve 'exports' in '/home/trex/dev/myapp'
@ ./node_modules/angular/index.js 1:0-20
@ ./app/bootstrap.js
我如何可以設置我的情況下,出口?
應用結構:
[email protected]:~/dev$ tree -L 1 myapp
theapp
├── app
├── css
├── font-awesome
├── fonts
├── img
├── index.html
├── lang
├── lib
├── node_modules
├── package.json
├── README.md
├── resources
├── scripts
├── share
├── templates
├── tests
└── widgets
一些庫在node_modules
,其他在lib
文件夾中。所有庫index.html中直接連接: <script type="application/javascript" src="lib/angular/angular.min.js" ></script>
的WebPack配置:
- MyApp的/應用/ app.js https://gist.github.com/sergibondarenko/a87578e774ca43f4fc8a105fa163e13c
- MyApp的:源代碼的
[email protected]:~/dev$ cat myapp/webpack.config.js var webpack = require('webpack'); var path = require('path'); module.exports = { entry: "./app/bootstrap.js", output: { path: __dirname + '/dist/', filename: "bundle.js" }, module: { loaders: [ { test: /\.css$/, loader: "style!css" }, { test: /[\/]angular\.js$/, loader: "exports?angular" } ] }, resolve: { alias: {}, extensions: ['.js', '.json'], modules: [ 'node_modules', 'lib' ] } };
件/app/main.js https://gist.github.com/sergibondarenko/9ea25e6ac4f57a7f2703e053efe48ca
- myapp/app/controllers/loginController.js https://gist.github.com/sergibondarenko/7c5df871c96f4e9919900f8f87d53a8b
--- UPDATE
我轉換的代碼ES6。
- MYAPP /應用/ app.js https://gist.github.com/sergibondarenko/73aa1ba06250c1d347bc44c7b9361c79
- MYAPP /應用/ main.js https://gist.github.com/sergibondarenko/ac290eb35f633337edd6ec8d15ccd13b
- MYAPP /應用/控制器/ loginController.js https://gist.github.com/sergibondarenko/9c995b4cab2de5d48905bac51c929155
現在我有以下錯誤:
[email protected]:~/dev/myapp$ webpack
Hash: 673f49fc25bd759ea99d
Version: webpack 3.4.1
Time: 118ms
Asset Size Chunks Chunk Names
bundle.js 18.2 kB 0 [emitted] main
[1] ./app/bootstrap.js 78 bytes {0} [built]
[2] ./app/app.js 7.35 kB {0} [built]
[3] ./app/services/routeResolver.js 7.07 kB {0} [built]
+ 1 hidden module
ERROR in ./node_modules/angular/index.js
Module not found: Error: Can't resolve 'exports' in '/home/trex/dev/myspp'
@ ./node_modules/angular/index.js 1:0-20
@ ./app/bootstrap.js
可以提供bootstrap.js和./node_modules/angular/index.js文件? node_modules究竟有什麼角度版本? –