requirejs使用r.js打包项目

发布于 2022-09-06 02:13:50 字数 7890 浏览 29 评论 0

项目使用的是requirejs + angularjs架构,初版完成了,需要打包js 文件,打算用requirejs的r.js打包成把src目录下的所有js文件和css文件打包成一个 js文件。 网络上收了写其他人写的build.js,照着写了 一份,但是运行报错了;

项目目录
clipboard.png

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
报错:

clipboard.png

这个错误 改如何解决? 困扰我几天了!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文