Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 提供预先制作的gzip文件_Node.js_Webpack_Gzip - Fatal编程技术网

Node.js 提供预先制作的gzip文件

Node.js 提供预先制作的gzip文件,node.js,webpack,gzip,Node.js,Webpack,Gzip,在捆绑过程中,我使用压缩网页包插件制作gzip文件,所以当捆绑完成后,我的dist文件夹中会有类似的文件 bundle.eefaef91f71795847e74.js bundle.eefaef91f71795847e74.js.gz vendor.jduu4f4lj71759dj7e74.js vendor.jduu4f4lj71759dj7e74.js.gz stylesLocal.b7ac53d721aca93e4e65099cf74dc90f.css stylesLocal.b7ac53

在捆绑过程中,我使用压缩网页包插件制作gzip文件,所以当捆绑完成后,我的dist文件夹中会有类似的文件

bundle.eefaef91f71795847e74.js
bundle.eefaef91f71795847e74.js.gz
vendor.jduu4f4lj71759dj7e74.js
vendor.jduu4f4lj71759dj7e74.js.gz
stylesLocal.b7ac53d721aca93e4e65099cf74dc90f.css
stylesLocal.b7ac53d721aca93e4e65099cf74dc90f.css.gz
在我用来提供gzip文件的服务器内部。为什么这不起作用。我的页面甚至不想加载?如果我将Express.static替换为expressStaticGzip,它会正常工作

import Express from 'express'
import path from 'path'
import conf from './conf'
import appRenderer from './appRenderer'
import webpackUtils from './webpackUtils'
var expressStaticGzip = require('express-static-gzip')

const APP_PORT: number = conf.APP_PORT
const PORT: any = process.env.PORT || APP_PORT

const app: Express = new Express()

app.set('views', path.join(__dirname, 'views'))
app.set('view engine', 'ejs')

app.use(expressStaticGzip(path.join(__dirname, '../', 'dist')))

/* check with the server before using the cached resource */
app.use((req: Object, res: Object, next: () => void): void => {
  res.set('Cache-Control', 'no-cache')
  return next()
})

/* Use server side rendering for first load */
app.use(appRenderer)

/* Use CommonChunks and long term caching */
app.use(webpackUtils)

// Routes
app.get('*', (req: Object, res: Object) => {
  res.render('index', {app: req.body})
})

app.listen(PORT, () => {
  console.log(`
  Express server is up on port ${PORT}
  Production environment
  `)
})
我在index.ejs文件中引用它们

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />

    <title>D</title>

      <link rel='stylesheet' type='text/css' href="stylesLocal.b7ac53d721aca93e4e65099cf74dc90f.css">
</head>

  <body>

      <div id="app"><%- app %></div>
      <script src="vendor.jduu4f4lj71759dj7e74.js"></script>
      <script src="bundle.eefaef91f71795847e74.js"></script>

  </body>
</html>

D
如中所述,语法与
express.static
略有不同

而不是

app.use(expressStaticGzip(path.join(__dirname, '../', 'dist')))
试一试

app.use('/', expressStaticGzip(path.join(__dirname, '../', 'dist')))