这是目录结构
该文件为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',
})
]
}