webpack-contrib/expose-loader

File hashes change between OSs when using expose-loader to replace jQuery and $

pydolan opened this issue · 2 comments

  • Operating System: Mac 10.14 & Ubuntu 16.04
  • Node Version: v12.6.0 (on mac); v12.13.0 (on ubuntu)
  • NPM Version: 6.9.0 (on mac); 6.12.0 (on ubuntu)
  • webpack Version: 4.32.2
  • expose-loader Version: 0.7.5

This issue is for a:

  • bug
  • feature request
  • modification request

Code

webpack.config.js
const path = require("path");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");

module.exports = {
  context: __dirname,
  entry: "./static/js/site.js",
  output: {
    path: path.resolve("./static/dist/"),
    filename: "[name]-[contenthash:8].js",
    publicPath: "/static/static/dist/"
  },
  devtool: 'false',
  module: {
    rules: [
      {
        test: require.resolve("jquery"),
        loader: "expose-loader?jQuery!expose-loader?$"
      },
      {
        test: /\.js$/,
        loader: "babel-loader",
        exclude: /node_modules/,
        options: {
          presets: ["@babel/preset-env"]
        }
      },
      {
        test: /\.(sa|sc|c)ss$/,
        use: ["css-loader", "sass-loader"]
      },
      {
        test: /.(jpg|png|woff(2)?|eot|ttf|svg)$/,
        loader: "file-loader",
        options: {
          name: "[name]-[contenthash:8].[ext]"
        }
      }
    ]
  },
  plugins: [
    new CleanWebpackPlugin()
  ],
  optimization: {
    minimize: false
  }
};
// site.js

import $ from 'jquery';
import 'bootstrap-sass';

$(document).ready(() => {
  console.log("page done.");
});

Expected Behavior

When building (via npm build command NODE_ENV=production webpack --mode production), the hash of the produced site-<hash>.js file should match on all operating systems.

Actual Behavior

When building on Mac vs. Linux, the hash differs.

How Do We Reproduce?

Use the above config. I can provide more info if needed.

Thanks for issue

@pydolan maybe this issue can be resolved by this PR in pending: #59.

You can try to follow this article as described in the last comment: https://medium.com/@the_teacher/webpack-different-assets-hashes-on-different-machines-the-problem-the-solution-ec6383983b99