2016-01-23 83 views
1

我在解决网址问题时遇到了问题。在我的本地节点服务器上运行时(因为它很方便),它的功能就像一个魅力,但是当我将它上传到我的服务器时,如果我把它放在一个子文件夹中(http://hostname.com/folder),就会停止工作。Webpack网址不正确

我在JS中加载的图像需要中断。它们位于我的项目根目录中的“资产”文件夹内。但它在服务器的根目录中搜索。

的WebPack配置:

var webpack = require('webpack'); 
var ExtractTextPlugin = require('extract-text-webpack-plugin'); 
var path = require('path'); 

var config = require('./_config'); //paths config.. 

module.exports = { 
    entry: [ 
     config.build('js', 'src'), //JavaScript entry point 
     config.build('css', 'src'), //CSS entry point 
    output: { 
     path: config.js.dest.path, 
     filename: config.js.dest.file //JavaScript end point 
    }, //quickest, webpack -d -p for production 
    devtool: 'eval', 
    module: { 
     //test: which filetype?, 
     //exclude: which folders to exclude 
     loaders: [{ 
      test: /\.js$/, 
      exclude: /node_modules/, 
      loader: 'babel', 
      query: { 
       babelrc: path.join(__dirname, '.babelrc') 
      } 
     }, { 
      test: /\.js$/, 
      exclude: /node_modules/, 
      loader: 'eslint' 
     }, { 
      test: /\.scss$/, 
      loader: ExtractTextPlugin.extract('css!postcss!sass?outputStyle=expanded') 
     }, { 
      test: /\.json$/, 
      loader: 'file?hash=sha512&digest=hex&name=../assets/[hash].[ext]' 
     }, { 
      test: /\.(jpe?g|png|gif|svg)$/i, 
      loaders: [ 
       'file?hash=sha512&digest=hex&name=../assets/[hash].[ext]', 
       'image-webpack?{progressive:true, optimizationLevel: 7, interlaced: false, pngquant:{quality: "65-90", speed: 4}}' 
      ] 
     }] 
    }, postcss: function(){ 
     return [ 
      require('postcss-will-change'), 
      require('postcss-cssnext')({ 
       browsers: ['IE >= 10', 'last 2 version'], 
       features: { 
        autoprefixer: { 
         cascase: false 
        } 
       } 
      }) 
     ] 
    }, //webpack plugins 
    plugins: [ 
     new webpack.optimize.DedupePlugin(), 
     //extract CSS into seperate file 
     new ExtractTextPlugin(
      config.build('css', 'dest') 
     ) 
    ], eslint: { 
     configFile: path.join(__dirname, '.eslintrc'), 
     ignorePath: path.join(__dirname, '.eslintignore') 
    }, resolve: { 
     extensions: ['', '.json', '.js', '.css'], 
     fallback: path.join(__dirname, 'node_modules') 
    }, resolveLoader: { 
     fallback: path.join(__dirname, 'node_modules') 
    } 
}; 

提前感谢!

回答

0

publicPath设置为指向您的资产目录。例如:

​​

此外,你需要调整你这样的装载机的定义:

loader: 'file?hash=sha512&digest=hex&name=./assets/[hash].[ext]' 

做这些调整后,您的应用程序运行,我没有任何错误。

+0

我想你的解决方案,但仍然没有更迭: 'Phaser.Loader - 图像[cuberdon]:从URL /资产/../资产错误装载资产/ 58e500fe3b4f0ae0d28707150235895f.png' –

+0

你能上建立一个可运行的例子GitHub的?没有具体的事情很难说。 'publicPath'显然是在做一些事情。我只是不确定那个'...'。 –

+0

你可以在这里找到它:https://github.com/JannesV/Major3这是一个学校项目,所以不要期望太多:) –