首页 > 页面使用ajax加载页面后如果运行其中的js,webpack如何多页面展示

页面使用ajax加载页面后如果运行其中的js,webpack如何多页面展示

1.页面使用了sui-mobile这个框架,其中的页面路由部分会使用ajax加载页面。虽然每次都能加载到下一个页面,但是会出现加载到的页面中的js不去执行的情况。

2.页面打包使用了webpack,现在出现的情况是打包的时候会把所有引用的代码都打包到一个js文件当中。我想要的是每个页面都能引入自己页面的js代码,然后能把每个页面相同的引用给合并成一个文件。现在的webpack.config:

var path = require('path');
var webpack = require('webpack')

module.exports = {
  entry:{
     index:'page/index/index.js'
  },
  output: {
    path:  path.normalize(__dirname+ "/public/html5/build/"),
    filename: '[name].bundle.js',
    publicPath: '/build/'
  },
  module: {
    loaders: [
      {
        test: /\.jsx?$/,
        exclude: /(node_modules|bower_components)/,
        loader: 'babel',
        query: {
          presets: ['react', 'es2015']
        }
      },
      {test: /\.css$/, loader: 'style!css'}
    ]
  },
  resolve : {
     root : [path.normalize(__dirname+'/public/html5/src/')],
     alias: {},
     extensions: ['', '.js', '.css', '.scss', '.ejs', '.png', '.jpg']
  },
  plugins: [
    new webpack.BannerPlugin('This file is created by douban')
  ]
}
【热门文章】
【热门文章】