0

现在部分疯了。我一直试图解决这个问题一个多星期,但仍然无法解决它。Webpack正在显示空白页面,但文件显示在终端

目前,我试图让React应用程序,利用React-Router,但我不使用ReduxFlux。我从react-redux-starter-kit获取了代码。我已经尝试了一下,并且一切正常,但是当我开始改变事情的时候,是在遇到问题时。

问题是,当页面加载时没有显示任何东西。当我什么也没说时,我的意思是没有HTMLJSCSS。所有正在显示的是由<header><body>标记组成的原始基地HTML文件。当启动终端,我可以看到的是,文件正在由webpack加载,这里是什么样子:

Server is now running at http://192.168.0.9:3000. 
webpack built 928ca955f4efc3417ea7 in 11490ms 
Hash: 928ca955f4efc3417ea7 
Version: webpack 1.13.2 
Time: 11490ms 
            Asset  Size Chunks    Chunk Names 
    2abdf22181eb309fd513564971a12163.png 70.2 kB   [emitted] 
    148e6bc6eabab75f3e18eddc2d99a10f.png  34 kB   [emitted] 
      app.928ca955f4efc3417ea7.js 1.04 MB  0 [emitted] app 
    1.charities.928ca955f4efc3417ea7.js 2.31 kB  1 [emitted] charities 
     vendor.928ca955f4efc3417ea7.js  405 kB  2 [emitted] vendor 
     app.928ca955f4efc3417ea7.js.map 1.29 MB  0 [emitted] app 
1.charities.928ca955f4efc3417ea7.js.map 3.53 kB  1 [emitted] charities 
    vendor.928ca955f4efc3417ea7.js.map  487 kB  2 [emitted] vendor 
          favicon.ico 30.9 kB   [emitted] 
          index.html 491 bytes   [emitted]  
Child html-webpack-plugin for "index.html": 
     Asset Size Chunks  Chunk Names 
    index.html 565 kB  0   
webpack: bundle is now VALID. 

当我加载页面,虽然,被显示没有这些项目的。我认为html-webpack-plugin是想要注入必要的文件,但它并没有这样做。我不知道为什么没有必要的文件被加载到我的HTML文件。我的WebPack配置是这样:

import webpack from 'webpack' 
import cssnano from 'cssnano' 
import postcssNested from 'postcss-nested' 
import postcssSimpleVars from 'postcss-simple-vars' 
import HtmlWebpackPlugin from 'html-webpack-plugin' 
import config from '../config' 

const paths = config.utils_paths 
const {__PROD__} = config.globals 

const webpackConfig = { 
    name: 'client', 
    target: 'web', 
    devtool: config.compiler_devtool, 
    resolve: { 
    root: paths.client(), 
    extensions: ['', '.js', '.json'] 
    }, 
    module: {} 
} 

const APP_ENTRY_PATHS = [ 
    'babel-polyfill', 
    paths.client('main.js'), 
    `webpack-hot-middleware/client?path=${config.compiler_public_path}__webpack_hmr` 
] 

webpackConfig.entry = { 
    app: APP_ENTRY_PATHS, 
    vendor: config.compiler_vendor 
} 

webpackConfig.output = { 
    filename: `[name].[${config.compiler_hash_type}].js`, 
    path: paths.dist(), 
    publicPath: config.compiler_public_path 
} 

webpackConfig.plugins = [ 
    new webpack.DefinePlugin(config.globals), 
    new HtmlWebpackPlugin({ 
    template: paths.client('index.html'), 
    hash: false, 
    favicon: paths.client('static/favicon.ico'), 
    filename: 'index.html', 
    inject: 'body', 
    minify: { 
     collapseWhitespace: true 
    } 
    }), 
    new webpack.HotModuleReplacementPlugin(), 
    new webpack.NoErrorsPlugin(), 
    new webpack.optimize.CommonsChunkPlugin({ 
    names: ['vendor'] 
    }) 
] 

if (__PROD__) { 
    webpackConfig.plugins.push(
    new webpack.optimize.OccurrenceOrderPlugin(), 
    new webpack.optimize.DedupePlugin(), 
    new webpack.optimize.UglifyJsPlugin({ 
     compress: { 
     unused: true, 
     dead_code: true, 
     warnings: false 
     } 
    }) 
) 
} 

webpackConfig.module.loaders = [ 
    { 
    test: /\.js$/, 
    exclude: /node_modules/, 
    loader: 'babel', 
    query: { 
     plugins: ['transform-runtime'], 
     presets: ['es2015', 'react', 'stage-1'] 
    } 
    }, 
    { 
    test: /\.json$/, 
    loader: 'json' 
    } 
] 

const BASE_CSS_LOADER = 'css?sourceMap&-minimize' 

const cssModulesRegex = new RegExp(
    `(${paths.client().replace(/[\^\$\.\*\+\-\?\=\!\:\|\\\/\(\)\[\]\{\}\,]/g, '\\$&')})` 
) 

const cssModulesLoader = [ 
    BASE_CSS_LOADER, 
    'modules', 
    'importLoaders=1', 
    'localIdentName=[name]__[local]___[hash:base64:5]' 
].join('&') 

webpackConfig.module.loaders.push({ 
    test: /\.css$/, 
    include: cssModulesRegex, 
    loaders: [ 
    'style', 
    cssModulesLoader, 
    'postcss' 
    ] 
}) 

webpackConfig.module.loaders.push({ 
    test: /\.css$/, 
    exclude: cssModulesRegex, 
    loaders: [ 
    'style', 
    BASE_CSS_LOADER, 
    'postcss' 
    ] 
}) 

webpackConfig.postcss = [ 
    cssnano({ 
    autoprefixer: { 
     add: true, 
     remove: true, 
     browsers: ['last 2 versions'] 
    }, 
    discardComments: { 
     removeAll: true 
    }, 
    discardUnused: false, 
    mergeIdents: false, 
    reduceIdents: false, 
    safe: true, 
    sourcemap: true 
    }), 
    postcssNested(), 
    postcssSimpleVars({ 
    variables: function() { 
     return require(paths.client('styles/variables')); 
    } 
    }) 
] 

webpackConfig.module.loaders.push(
    { test: /\.woff(\?.*)?$/, loader: 'url?prefix=fonts/&name=[path][name].[ext]&limit=10000&mimetype=application/font-woff' }, 
    { test: /\.woff2(\?.*)?$/, loader: 'url?prefix=fonts/&name=[path][name].[ext]&limit=10000&mimetype=application/font-woff2' }, 
    { test: /\.otf(\?.*)?$/, loader: 'file?prefix=fonts/&name=[path][name].[ext]&limit=10000&mimetype=font/opentype' }, 
    { test: /\.ttf(\?.*)?$/, loader: 'url?prefix=fonts/&name=[path][name].[ext]&limit=10000&mimetype=application/octet-stream' }, 
    { test: /\.eot(\?.*)?$/, loader: 'file?prefix=fonts/&name=[path][name].[ext]' }, 
    { test: /\.svg(\?.*)?$/, loader: 'url?prefix=fonts/&name=[path][name].[ext]&limit=10000&mimetype=image/svg+xml' }, 
    { test: /\.(png|jpg)$/, loader: 'url?limit=8192' } 
) 

export default webpackConfig 

请帮我弄清楚,为什么我的index.html不被任何有需要的文件的注入。所有正在显示的是原始的index.html。如果你想要我目前使用的所有文件,你可以查看它们here。谢谢,请帮助!

+0

你什么都看不到或者什么都没有? :)浏览器的开发者控制台是否显示任何内容?那里有错误吗?也许你的JS代码冻结了浏览器? – EugZol

+0

你好@EugZol,其实没什么可悲的!实际上唯一的东西就是普通的'index.html'。 –

回答

1

它看起来像所有这一切被服务是后备和静态处理您在server/main.js

app.use(express.static(root)); 
app.use(fallback('index.html', { root })); 

配置如果删除该请求无限期挂起。这不是唯一必要的解决方法,但希望能帮助你解决问题的根源。

+0

你好,所以问题的根源在于请求没有正确路由,因此这是一个服务器问题?当我有时间时,我会试着今晚测试这个!谢谢 –

+0

是的,对不起,这个代码库有很多我不熟悉的东西,我真的没有时间去挖掘它。希望别人能够帮助更多! –

+0

不,谢谢!我很高兴你甚至看了:)现在我知道我可能需要专注于路线。 –