【问题标题】:Using Webpack 4 can access the hash or contenthash in my javascript code, not the html?使用 Webpack 4 可以访问我的 javascript 代码中的 hash 或 contenthash,而不是 html?
【发布时间】:2018-12-07 18:42:21
【问题描述】:

如何在我的代码中访问 [name] 和 [contenthash]。

我希望我的 loader.js 文件引用其他脚本的文件名。

webpack.config.js:

module.exports = {
  entry: {
    app: './src/index.js',
    loader: './src/loader.js'
  },
  output: {
    filename: '[name].[contenthash].js',
    path: path.resolve(__dirname, 'dist')
  },
}

【问题讨论】:

    标签: webpack


    【解决方案1】:

    添加 ExtendedAPIPlugin

    new webpack.ExtendedAPIPlugin()
    

    __webpack_hash__ 是全球性的,您可以在任何地方访问。

    【讨论】:

    • 在我的捆绑脚本中使用时会显示:ReferenceError: webpack_hash is not defined
    • 我们只需要添加这个插件 new webpack.ExtendedAPIPlugin() 来使用那个全局变量 webpack_hash
    猜你喜欢
    • 1970-01-01
    • 2011-04-21
    • 1970-01-01
    • 2017-03-15
    • 2012-12-13
    • 2012-09-24
    • 1970-01-01
    • 2019-02-10
    • 1970-01-01
    相关资源
    最近更新 更多