search

Home  >  Q&A  >  body text

angular.js - Several problems with webpack packaging projects?

I recently used webpack to package the angular1. folder, can’t the path of templateUrl in my routing configuration be hard-coded directly?

//app.config.js
routing.$inject = ['$stateProvider', '$urlRouterProvider', '$locationProvider'];

export default function routing($stateProvider, $urlRouterProvider, $locationProvider){
    $urlRouterProvider.otherwise('/home');

    $stateProvider
        .state('home', {
            url: '/home',
            templateUrl: 'views/home.html',
            controller: 'HomeController'
        })
};

2. There are many img srcs in the page, but the paths are wrong after packaging?

<img src="../img/ico_why.png"/>

After using

it seems that the path is wrong too ng-src

3. When using a third-party plug-in, it needs to configure the location of a plug-in

, but after packaging, the path is still wrongbasePath

I feel that the webpack packaging path is very unclear, and various errors are reported!

世界只因有你世界只因有你2797 days ago494

reply all(1)I'll reply

  • PHPz

    PHPz2017-05-15 17:07:16

    Why don’t you import the html template and use that template:
    https://github.com/hjzheng/an...
    Share a piece of code I wrote before:

    import template from './dashboard.partial.html';
    import DashboardCtrl from './DashboardCtrl';
    
    function router($stateProvider, $urlRouterProvider) {
    
        $stateProvider
            .state('dashboard', {
                url: '/dashboard',
                template: template,
                label: 'Dashboard',
                icon: 'glyphicon-dashboard',
                controller: DashboardCtrl,
                controllerAs: '$ctrl'
            });
    
        $urlRouterProvider.otherwise('/dashboard');
    }
    
    router.$inject = ['$stateProvider', '$urlRouterProvider'];
    
    export default router;
    

    As for the image path, I haven’t really studied it. Our products mainly use iconfont, so I’m looking for an answer

    reply
    0
  • Cancelreply