akejolin / snowpack-plugin-content-hash

A small snowpack plugin which will add a content hash to all your imports paths on build command.
MIT License
8 stars 4 forks source link

[Object object] in the output index.html file #6

Open ivmel-ca opened 3 years ago

ivmel-ca commented 3 years ago

Hi there! I have an issue with the plugin. After configuring my snowpack config and running snowpack build it outputs an html file with an object in the path to a hashed js file).

my snowpack config:

// Snowpack Configuration File
// See all supported options: https://www.snowpack.dev/reference/configuration

/** @type {import("snowpack").SnowpackUserConfig } */

const fs = require('fs');
const path = require('path');

// those files haven't been found in either webpack or snowpack

/* const cert = fs.readFileSync(
  path.resolve(__dirname, '../c../certs/bitstocks.local/bitstocks.local.crt'),
);
const key = fs.readFileSync(
  path.resolve(__dirname, '../certs/bitstocks.local/bitstocks.local.priv.key'),
); */

// To generate certification and key run in the console:
// npx devcert-cli generate localhost

const cert = fs.readFileSync('./localhost.cert');
const key = fs.readFileSync('./localhost.key');

module.exports = {
  mount: {
    static: { url: '/', static: true },
    src: { url: '/dist' },
  },
  plugins: [
    '@snowpack/plugin-react-refresh',
    '@snowpack/plugin-babel',
    '@snowpack/plugin-sass',
    ['snowpack-plugin-svgr', { exclude: '*/**/node_modules' }],
    [
      'snowpack-plugin-content-hash',
      {
        exts: ['.js', '.jsx'], // Extensions of files to be affected by this plugin. Note: only .js or .jsx are valid extensions.
        silent: true, // Provide log output during build process. Default: true.
        hashLength: 8, // Specify the max length of the resulting hash string. Defaults to 0 for the full length.
        hashAlgorithm: 'md5', // Specify the hash algorithm. Defaults to md5.
      },
    ],
  ],
  devOptions: {
    port: 3000,
    secure: { cert, key },
  },
  alias: {
    $components: path.resolve(__dirname, 'src/components'),
    $constants: path.resolve(__dirname, 'src/constants'),
    $hoc: path.resolve(__dirname, 'src/hoc'),
    $pages: path.resolve(__dirname, 'src/pages'),
    $state: path.resolve(__dirname, 'src/state'),
    $svgs: path.resolve(__dirname, 'src/svgs'),
    $utils: path.resolve(__dirname, 'src/utils'),
    $hooks: path.resolve(__dirname, 'src/hooks'),
    scss: path.resolve(__dirname, 'src/scss'),
    $hooks: path.resolve(__dirname, 'src/hooks'),
  },
  optimize: {
    bundle: true,
    minify: true,
    target: 'es2018',
  },
  buildOptions: {
    /* ... */
  },
};

package.json:

  "name": "snowpack-test",
  "version": "1.0.0",
  "description": "a pet project to try out snowpack configurations",
  "main": "index.js",
  "scripts": {
    "start": "snowpack dev",
    "build": "snowpack build",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "ivmel.ca",
  "license": "ISC",
  "devDependencies": {
    "@babel/cli": "^7.13.16",
    "@babel/core": "^7.13.16",
    "@babel/preset-env": "^7.13.15",
    "@babel/preset-react": "^7.13.13",
    "@snowpack/babel-plugin-package-import": "^1.1.6",
    "@snowpack/plugin-babel": "^2.1.7",
    "@snowpack/plugin-dotenv": "^2.1.0",
    "@snowpack/plugin-react-refresh": "^2.4.2",
    "@snowpack/plugin-sass": "^1.4.0",
    "live-server": "^1.2.1",
    "snowpack": "^3.3.5",
    "snowpack-plugin-content-hash": "^1.2.1",
    "snowpack-plugin-svgr": "^0.1.2"
  },
  "dependencies": {
    "react": "^17.0.2",
    "react-dom": "^17.0.2"
  }
}

generated html:

    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Snowpack Test</title>
  <link rel="stylesheet" href="/dist/index.css"></head>
  <body>
    <div id="app"></div>
    <script type="module" src="dis[object Object]/index.js"></script>
</body></html>
fakership commented 3 years ago

the js in html can not be replaced with hash