yyc13579 2017-08-01 02:55 采纳率: 0%
浏览 1501

webpack打包后,找不到angular state中templateUrl路径,该如何配置?

这是目录结构

图片说明

该文件为bike.js

angular.module('bike', ['ui.router', 'bike.services', 'oc.lazyLoad'])
.config(function ($stateProvider, $urlRouterProvider) {

    $stateProvider
        .state('map', {
            url: '/map',
            templateUrl: '../html/map.html',
            cache: false,
            controller: 'mapCtrl',
            resolve: {
                loadMyCtrl: function ($ocLazyLoad) {
                    return $ocLazyLoad.load({
                        files: [
                            "../js/beforejs/map.js"
                        ]
                    })
                }
            }
        })

    $urlRouterProvider.otherwise('map');
})

.run(function ($rootScope, $templateCache) {
    $rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) {
        console.log(fromState.url)
        if (fromState.url == "/map") {
        clearInterval($rootScope.map_intervar)
           }
        if (typeof(toState) !== 'undefined' && toState.templateUrl) {
            $templateCache.remove(fromState.templateUrl);
        }
        $templateCache.removeAll();
    });
})

webpack.config.js

var HtmlWebpackPlugin = require("html-webpack-plugin");
var webpack = require("webpack");

module.exports = {
entry: {
// "vuedata":__dirname + "/public/js/vuedata.js",
"beforejs/bike":__dirname + "/public/js/beforejs/bike.js",
"beforejs/map":__dirname + "/public/js/beforejs/map.js",
"index":__dirname + "/public/js/index.js"
},
output: {
path: __dirname + "/public/webapp/js",
filename: "[name].js"
},
resolve: {
alias: {
vue:"vue/dist/vue.js"
}
},
module: {
loaders: [
{
test:/.js$/,
loader: "babel-loader"
}
]
},
plugins: [
new HtmlWebpackPlugin({
filename: __dirname+'/public/webapp/index.html',
template: __dirname+'/public/html/index.html',
inject:'body',
hash:true,
chunks:["beforejs/bike","index"]
}),
new HtmlWebpackPlugin({
filename: __dirname+'/public/webapp/html/map.html',
template: __dirname+'/public/html/map.html',
})
]
}

  • 写回答

1条回答 默认 最新

  • dabocaiqq 2018-06-26 16:09
    关注
    评论

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致