requirejs使用r.js打包项目
项目使用的是requirejs + angularjs架构,初版完成了,需要打包js 文件,打算用requirejs的r.js打包成把src目录下的所有js文件和css文件打包成一个 js文件。 网络上收了写其他人写的build.js,照着写了 一份,但是运行报错了;
项目目录
main.js代码
require.config({
// 配置基础目录路径
baseUrl: 'src',
// 配置文件路径
paths: {
'css': '../vendor/require-css/css.min',
'jquery': '../vendor/jquery/jquery.min',
'bootstrap': '../vendor/bootstrap/js/bootstrap.min',
'bootstrapSwitch': '../vendor/bootstrap/js/bootstrap-switch.min',
'angular': '../vendor/angular/angular.min',
'uiRouter': '../vendor/angular-ui-router/angular-ui-router.min',
'ngCookies': '../vendor/angular-cookie/angular-cookie.min',
'ngMessages': '../vendor/angular-message/angular-message.min',
'pascalprechtTranslate': '../vendor/angular-translate/angular-translate.min',
'loaderStaticFiles': '../vendor/angular-translate/angular-translate-loader-static-files',
'icheck': '../vendor/icheck/icheck.min',
'echarts': '../vendor/echarts/echarts.min',
'app': '../app',
'allControllers': 'controllers/allControllers',
'allDirectives': 'directives/allDirectives',
'allServers': 'servers/allServers',
'allFilters': 'filters/allFilters',
'appController': 'controllers/appController',
'contentController': 'controllers/contentController',
'setController': 'controllers/setController',
'loginController': 'controllers/loginController',
'pwdController': 'controllers/pwdController',
'behaviorController': 'controllers/behaviorController',
'securityController': 'controllers/securityController',
'vpnController': 'controllers/vpnController',
'authController': 'controllers/authController',
'advanceController': 'controllers/advanceController',
'systemController': 'controllers/systemController',
'linkProtectController': 'controllers/linkProtectController',
'statusController': 'controllers/statusController',
'topDirective': 'directives/topDirective',
'navDirective': 'directives/navDirective',
'statusDirective': 'directives/statusDirective',
'icheckDirective': 'directives/icheckDirective',
'commonDirective': 'directives/commonDirective',
'contentDirective': 'directives/contentDirective',
'myUntil': 'servers/myUntil',
'dataServer': 'servers/dataServer',
'selectServer': 'servers/selectServer',
'sessionServer': 'servers/sessionServer',
'userAuthServer': 'servers/userAuthServer',
'beforeUnload': 'servers/beforeUnload',
'localStorage': 'servers/localStorage',
'clientInfo': 'servers/clientInfo',
'translateFilter': 'filters/translateFilter'
},
// 配置依赖
shim: {
'angular': {
exports: 'angular',
deps: ['jquery']
},
'ngCookies': {
exports: 'ngCookies',
deps: ['angular']
},
'ngMessages': {
exports: 'ngMessages',
deps: ['angular']
},
'uiRouter': {
exports: 'uiRouter',
deps: ['angular']
},
'bootstrap': {
exports: '$',
deps: ['jquery', 'css!../vendor/bootstrap/css/bootstrap.min.css']
},
'pascalprechtTranslate': {
exports: 'pascalprechtTranslate',
deps: ['angular']
},
'echarts': {
exports: 'echarts'
},
'bootstrapSwitch': {
deps: ['bootstrap', 'css!../vendor/bootstrap/css/bootstrap-switch.min.css']
},
'icheck': {
exports: 'icheck',
deps: ['jquery']
},
'app': {
exports: 'app',
deps: ['bootstrap', 'echarts', 'angular', 'ngCookies', 'ngMessages', 'uiRouter', 'pascalprechtTranslate', 'css!static/css/main.css']
}
}
})
// 配置完毕后加载app.js文件
require(['app']);
build.js 代码
({
baseUrl: '.',
name:'main',
out:'./dist/main-built.js',
paths: {
'css': './vendor/require-css/css.min',
'jquery': './vendor/jquery/jquery.min',
'bootstrap': './vendor/bootstrap/js/bootstrap.min',
'bootstrapSwitch': './vendor/bootstrap/js/bootstrap-switch.min',
'angular': './vendor/angular/angular.min',
'uiRouter': './vendor/angular-ui-router/angular-ui-router.min',
'ngCookies': './vendor/angular-cookie/angular-cookie.min',
'ngMessages': './vendor/angular-message/angular-message.min',
'pascalprechtTranslate': './vendor/angular-translate/angular-translate.min',
'loaderStaticFiles': './vendor/angular-translate/angular-translate-loader-static-files',
'icheck': './vendor/icheck/icheck.min',
// 'echarts':'../vendor/echarts/echarts.min',
'echarts': './vendor/echarts/echarts.min',
// 'translateLocalStorage' : '../vendor/angular-translate/storage-local',
// 'translateCookieStorage' : '../vendor/angular-translate/storage-cookie',
'app': './app',
// 引入自定义依赖
'allControllers': 'controllers/allControllers',
'allDirectives': 'directives/allDirectives',
'allServers': 'servers/allServers',
'allFilters': 'filters/allFilters',
'appController': 'controllers/appController',
'contentController': 'controllers/contentController',
'setController': 'controllers/setController',
'loginController': 'controllers/loginController',
'pwdController': 'controllers/pwdController',
'behaviorController': 'controllers/behaviorController',
'securityController': 'controllers/securityController',
'vpnController': 'controllers/vpnController',
'authController': 'controllers/authController',
'advanceController': 'controllers/advanceController',
'systemController': 'controllers/systemController',
'linkProtectController': 'controllers/linkProtectController',
// 'loginDirective' : 'directives/loginDirective',
'topDirective': 'directives/topDirective',
'navDirective': 'directives/navDirective',
'statusDirective': 'directives/statusDirective',
'icheckDirective': 'directives/icheckDirective',
'commonDirective': 'directives/commonDirective',
'contentDirective': 'directives/contentDirective',
'myUntil': 'servers/myUntil',
'dataServer': 'servers/dataServer',
'selectServer': 'servers/selectServer',
'sessionServer': 'servers/sessionServer',
'userAuthServer': 'servers/userAuthServer',
'beforeUnload': 'servers/beforeUnload',
'localStorage': 'servers/localStorage',
'clientInfo': 'servers/clientInfo',
'translateFilter': 'filters/translateFilter'
},
// 配置依赖
shim: {
'angular': {
exports: 'angular',
deps: ['jquery']
},
'ngCookies': {
exports: 'ngCookies',
deps: ['angular']
},
'ngMessages': {
exports: 'ngMessages',
deps: ['angular']
},
'uiRouter': {
exports: 'uiRouter',
deps: ['angular']
},
'bootstrap': {
exports: '$',
deps: ['jquery', 'css!../vendor/bootstrap/css/bootstrap.min.css']
},
/* 'bPopup': {
exports: 'bPopup',
deps:['jquery']
},*/
'pascalprechtTranslate': {
exports: 'pascalprechtTranslate',
deps: ['angular']
},
'echarts': {
exports: 'echarts'
},
'bootstrapSwitch': {
deps: ['bootstrap', 'css!../vendor/bootstrap/css/bootstrap-switch.min.css']
},
'icheck': {
exports: 'icheck',
deps: ['jquery']
},
'app': {
exports: 'app',
deps: ['bootstrap', 'echarts', 'angular', 'ngCookies', 'ngMessages', 'uiRouter', 'pascalprechtTranslate', 'css!static/css/main.css']
}
},
})
进入rjs目录之后执行命令:node r.js -o build.js
报错:
这个错误 改如何解决? 困扰我几天了!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论