【问题标题】:Webpack Encore generates the right assets but with an empty Entrypoints.jsonWebpack Encore 生成正确的资产,但 Entrypoints.json 为空
【发布时间】:2023-03-30 10:12:01
【问题描述】:

这可能更像是一个理论问题,所以我将我的想法写下来......我在我们的 symfony 3.4 应用程序中用 webpack_encore 替换了资产。 Local 一切正常,但是当我通过 Jenkins 将它部署到我们的测试环境时,它会很好地生成所有资产,但是 Entrypoints.json 没有填充入口点信息,而是填充了一个(不存在的)文件。 Jenkins、Composer Install、NPM BUILD 等。一切都没有失败,一切看起来都很好......

我正在与:

  • "symfony/symfony": "3.4.*",
  • "symfony/webpack-encore-bundle": "^1.4",
  • "@symfony/webpack-encore": "^0.26.0";
  • 詹金斯版本。 2.167

我做过和检查过的事情:

  • webpack_encore 输出路径在 symfony 配置和 webpack.config.js 中设置;
  • 设置了读取/写入文件的权限(它们是在每次构建时新生成的)
  • 在不同的环境中尝试过(同样的问题,.json 中没有入口点)
  • 试图重现 lokal(没有完成)
  • 尝试了另一个节点版本(8.x)

这就是 Entrypoints.json 的样子:

{
  "entrypoints": {
    "main": {
      "js": [
        "/assets/main.d062ba67.js"
      ]
    }
  }
}

这里是生成文件的列表:

-rw-r--r-- 1 deploy deploy 1188442 Apr  4 16:03 0.2d854ee0.js
-rw-r--r-- 1 deploy deploy   13270 Apr  4 16:03 0.e9d891b2.css
-rw-r--r-- 1 deploy deploy     103 Apr  4 16:03 entrypoints.json
drwxr-xr-x 2 deploy deploy    4096 Jan 21 11:04 fonts
drwxr-xr-x 2 deploy deploy    4096 Jan 21 11:04 images
-rw-r--r-- 1 deploy deploy      50 Apr  4 16:03 manifest.json
-rw-r--r-- 1 deploy deploy  273060 Apr  4 16:03 mijn.51e8a5cf.css
-rw-r--r-- 1 deploy deploy  399784 Apr  4 16:03 mijn.b4e892a5.js
-rw-r--r-- 1 deploy deploy     155 Apr  4 16:03 mijn_servicecentre.8ad08279.js
-rw-r--r-- 1 deploy deploy    8867 Apr  4 16:03 mijn_servicecentre.aed8de72.css
-rw-r--r-- 1 deploy deploy  131539 Apr  4 16:03 mijn_translations.6510f7fd.js
-rw-r--r-- 1 deploy deploy    1463 Apr  4 16:03 runtime.3dee20dd.js

编辑:: 最后是 webpack.config.js

/* global __dirname */
let Encore = require("@symfony/webpack-encore");
const path = require("path");

Encore
// output path
    .setOutputPath("web/assets")
    .enableVersioning()

    // relative path in the browser
    .setPublicPath("/assets")

    // will create web/assets/mijn.js and web/assets/mijn.css && serviceCenter
    // which is than included in base.html.twig and respective...
    .addEntry("mijn", "./app/Resources/frontend/encore_mijn.js")
    .addEntry("mijn_servicecentre", "./app/Resources/frontend/encore_mijn_servicecentre.js")

    // enable sass-compilation
    .enableSassLoader(function (sassOptions) {
        sassOptions.includePaths = [
            "node_modules/bootstrap-sass/assets/stylesheets",
            "node_modules/bootstrap-datepicker/dist/css",
            "node_modules/bootstrap-select/sass",
            "node_modules/xs4-icons/dist/"
        ];
    }, {
        resolveUrlLoader: true
    })

    //expose jquery
    .addLoader({
        test: require.resolve("jquery"),
        use: [{
            loader: "expose-loader",
            options: "jQuery"
        }, {
            loader: "expose-loader",
            options: "$"
        }, {
            loader: "expose-loader",
            options: "Snow"
        }]
    })

    .addLoader({
        test: require.resolve("bazinga-translator"),
        use: [{
            loader: "expose-loader",
            options: "Translator"
        }],
    })

    .addLoader({
        loader: "webpack-modernizr-loader",
        test: /\.modernizrrc\.js$/
    })

    .addAliases({
        modernizr$: path.resolve(__dirname, "./.modernizrrc.js")
    })

    //enable compilation of vue-components
    .enableVueLoader()

    //enable sourcemaps for development reasons only
    .enableSourceMaps(!Encore.isProduction())

    // enable postcss loader for autoprefixing
    .enablePostCssLoader()

    // empty the outputPath dir before each build
    .cleanupOutputBeforeBuild()

    .enableSingleRuntimeChunk()

    .enableSingleRuntimeChunk()

    .splitEntryChunks()
;

// isProduction because we get in dev-mode real-time translation
// out of _translations.html.twig and the bazinga vendor plugin
if (Encore.isProduction()) {
    Encore.addEntry("mijn_translations", "./app/Resources/frontend/encore_translations.js")
}

// export the final configuration
module.exports = Encore.getWebpackConfig();

是否有人想过,入口点文件如何生成得很好,但入口点.json 没有填充?

编辑 2::

我再次运行我的所有提交,看起来自从我升级了 npm 包:webpack-encore 从 0.20.1 到 0.21 这需要 babel7 打破...

【问题讨论】:

  • 也显示你的 webpack.config.js 文件

标签: symfony jenkins webpack webpack-encore


【解决方案1】:

除了你的双 .enableSingleRuntimeChunk() 行只是一个错字(但你永远不知道,这可能是罪魁祸首),我认为你想查看 manifest.json 文件而不是在您的实际文件和入口点之间进行匹配。

我不知道你想用 entrypoints.json 文件实现什么,但正如 stof 所说:“你仍然应该使用 manifest.json 来查找版本化路径对于他们每个人”(在https://github.com/symfony/webpack-encore/issues/355

【讨论】:

  • 感谢您的提示,仔细检查了运行时块,遗憾的是不是罪魁祸首。此外 manifest.json 的内容有点相同: { "assets/main.js": "/assets/main.713ede0b.js" }
  • 那么看起来您的 Jenkins 正在构建您的配置的不同版本(可能是缓存版本),或者输出了正确的文件其他地方 在你的系统上(如果你分开发布,可能在不同的发布文件夹中?)——我有一个非常相似的 webpack 配置,一切都很好。
  • 这也是我的想法,但同时我发现了错误:自从我运行 js-tests 时更新它创建了一个新的 entrypoints.json / manifest.json 而不是覆盖正确的。我没有深入挖掘为什么现在会发生这种情况,因为它是周末时间,但它与 mocha-webpack 包有关。
猜你喜欢
  • 1970-01-01
  • 2016-09-07
  • 1970-01-01
  • 1970-01-01
  • 2017-12-19
  • 2014-05-10
  • 2018-03-22
  • 2019-08-07
  • 2019-01-09
相关资源
最近更新 更多