Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Hard Issue] vite should not change importmap position in index.html #11304

Closed
7 tasks done
tjx666 opened this issue Dec 10, 2022 · 0 comments · Fixed by #11492
Closed
7 tasks done

[Hard Issue] vite should not change importmap position in index.html #11304

tjx666 opened this issue Dec 10, 2022 · 0 comments · Fixed by #11492

Comments

@tjx666
Copy link

tjx666 commented Dec 10, 2022

Describe the bug

origin index.html:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" href="/favicon.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Vite App</title>
    <script
      async
      src="https://esm.dancf.com/npm:es-module-shims@1.6.2/dist/es-module-shims.js"
      crossorigin="anonymous"
    ></script>
    <script type="importmap">
      {
        "imports": {
          "vue": "https://esm.dancf.com/npm:vue@2.7.14/dist/vue.runtime.esm.js"
        }
      }
    </script>
    <link
      rel="modulepreload"
      href="https://esm.dancf.com/npm:vue@2.7.14/dist/vue.runtime.esm.js"
    />
  </head>
  <body>
    <div id="app"></div>
    <script type="module" src="/src/main.ts"></script>
  </body>
</html>

After vite build, the importmap part is move after modulepreload which cause importmap not work.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" href="/favicon.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Vite App</title>
    <script
      async
      src="https://esm.dancf.com/npm:es-module-shims@1.6.2/dist/es-module-shims.js"
      crossorigin="anonymous"
    ></script>

    <link
      rel="modulepreload"
      href="https://esm.dancf.com/npm:vue@2.7.14/dist/vue.runtime.esm.js"
    />
    <script type="importmap">
      {
        "imports": {
          "vue": "https://esm.dancf.com/npm:vue@2.7.14/dist/vue.runtime.esm.js"
        }
      }
    </script>
    <script type="module" crossorigin src="/assets/index.15b38fe3.js"></script>
    <link rel="stylesheet" href="/assets/index.b9365240.css">
  </head>
  <body>
    <div id="app"></div>
    
  </body>
</html>

Reproduction

https://github.com/tjx666/vite-importmap/tree/main

Steps to reproduce

  1. git clone git@github.com:tjx666/vite-importmap.git
  2. pnpm install
  3. vite build
  4. check index.html and dist/index.html

System Info

System:
    OS: macOS 13.0.1
    CPU: (8) x64 Intel(R) Core(TM) i5-8257U CPU @ 1.40GHz
    Memory: 521.62 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.12.1 - ~/Library/Caches/fnm_multishells/5032_1670692281244/bin/node
    Yarn: 1.22.19 - ~/Library/Caches/fnm_multishells/5032_1670692281244/bin/yarn
    npm: 9.2.0 - ~/Library/Caches/fnm_multishells/5032_1670692281244/bin/npm
  Browsers:
    Chrome: 108.0.5359.98
    Firefox Developer Edition: 104.0
    Safari: 16.1
  npmPackages:
    @vitejs/plugin-vue: 4.0.0 => 4.0.0 
    @vitejs/plugin-vue-jsx: 3.0.0 => 3.0.0 
    vite: 4.0.0 => 4.0.0 


### Used Package Manager

pnpm

### Logs

<details>
<summary>Click to expand!</summary>

```shell
❯ vite build -d
  vite:config bundled config file loaded in 272.11ms +0ms
  vite:esbuild init tsconfck (root: /Users/yutengjing/code/vite-importmap) +0ms
  vite:esbuild init tsconfck (root: /Users/yutengjing/code/vite-importmap) +1ms
  vite:esbuild init tsconfck (root: /Users/yutengjing/code/vite-importmap) +1ms
  vite:esbuild init tsconfck (root: /Users/yutengjing/code/vite-importmap) +0ms
  vite:esbuild init tsconfck end +22ms
  vite:esbuild init tsconfck end +1ms
  vite:esbuild init tsconfck end +0ms
  vite:esbuild init tsconfck end +0ms
  vite:config using resolved config: {
  vite:config   plugins: [
  vite:config     'vite:build-metadata',
  vite:config     'vite:pre-alias',
  vite:config     'alias',
  vite:config     'vite:modulepreload-polyfill',
  vite:config     'vite:resolve',
  vite:config     'vite:html-inline-proxy',
  vite:config     'vite:css',
  vite:config     'vite:esbuild',
  vite:config     'vite:json',
  vite:config     'vite:wasm-helper',
  vite:config     'vite:worker',
  vite:config     'vite:asset',
  vite:config     'vite:vue',
  vite:config     'vite:vue-jsx',
  vite:config     'vite:wasm-fallback',
  vite:config     'vite:define',
  vite:config     'vite:css-post',
  vite:config     'vite:build-html',
  vite:config     'vite:worker-import-meta-url',
  vite:config     'vite:asset-import-meta-url',
  vite:config     'vite:force-systemjs-wrap-complete',
  vite:config     'vite:watch-package-data',
  vite:config     'commonjs',
  vite:config     'vite:data-uri',
  vite:config     'vite:dynamic-import-vars',
  vite:config     'vite:import-glob',
  vite:config     'vite:build-import-analysis',
  vite:config     'vite:esbuild-transpile',
  vite:config     'vite:terser',
  vite:config     'vite:reporter',
  vite:config     'vite:load-fallback'
  vite:config   ],
  vite:config   resolve: {
  vite:config     mainFields: [ 'module', 'jsnext:main', 'jsnext' ],
  vite:config     browserField: true,
  vite:config     conditions: [],
  vite:config     extensions: [
  vite:config       '.mjs',  '.js',
  vite:config       '.mts',  '.ts',
  vite:config       '.jsx',  '.tsx',
  vite:config       '.json'
  vite:config     ],
  vite:config     dedupe: [ 'vue' ],
  vite:config     preserveSymlinks: false,
  vite:config     alias: [ [Object], [Object], [Object] ]
  vite:config   },
  vite:config   optimizeDeps: {
  vite:config     disabled: 'build',
  vite:config     force: undefined,
  vite:config     esbuildOptions: { preserveSymlinks: false }
  vite:config   },
  vite:config   build: {
  vite:config     target: [ 'es2020', 'edge88', 'firefox78', 'chrome87', 'safari14' ],
  vite:config     cssTarget: [ 'es2020', 'edge88', 'firefox78', 'chrome87', 'safari14' ],
  vite:config     outDir: 'dist',
  vite:config     assetsDir: 'assets',
  vite:config     assetsInlineLimit: 4096,
  vite:config     cssCodeSplit: true,
  vite:config     sourcemap: false,
  vite:config     rollupOptions: {},
  vite:config     minify: 'esbuild',
  vite:config     terserOptions: {},
  vite:config     write: true,
  vite:config     emptyOutDir: null,
  vite:config     copyPublicDir: true,
  vite:config     manifest: false,
  vite:config     lib: false,
  vite:config     ssr: false,
  vite:config     ssrManifest: false,
  vite:config     reportCompressedSize: true,
  vite:config     chunkSizeWarningLimit: 500,
  vite:config     watch: null,
  vite:config     commonjsOptions: { include: [Array], extensions: [Array] },
  vite:config     dynamicImportVarsOptions: { warnOnError: true, exclude: [Array] },
  vite:config     modulePreload: { polyfill: true }
  vite:config   },
  vite:config   define: { __VUE_OPTIONS_API__: true, __VUE_PROD_DEVTOOLS__: false },
  vite:config   ssr: {
  vite:config     format: 'esm',
  vite:config     target: 'node',
  vite:config     external: [],
  vite:config     optimizeDeps: { disabled: true, esbuildOptions: [Object] }
  vite:config   },
  vite:config   esbuild: { include: /\.ts$/ },
  vite:config   configFile: '/Users/yutengjing/code/vite-importmap/vite.config.ts',
  vite:config   configFileDependencies: [ '/Users/yutengjing/code/vite-importmap/vite.config.ts' ],
  vite:config   inlineConfig: {
  vite:config     root: undefined,
  vite:config     base: undefined,
  vite:config     mode: undefined,
  vite:config     configFile: undefined,
  vite:config     logLevel: undefined,
  vite:config     clearScreen: undefined,
  vite:config     optimizeDeps: { force: undefined },
  vite:config     build: {}
  vite:config   },
  vite:config   root: '/Users/yutengjing/code/vite-importmap',
  vite:config   base: '/',
  vite:config   rawBase: '/',
  vite:config   publicDir: '/Users/yutengjing/code/vite-importmap/public',
  vite:config   cacheDir: '/Users/yutengjing/code/vite-importmap/node_modules/.vite',
  vite:config   command: 'build',
  vite:config   mode: 'production',
  vite:config   isWorker: false,
  vite:config   mainConfig: null,
  vite:config   isProduction: true,
  vite:config   server: {
  vite:config     preTransformRequests: true,
  vite:config     middlewareMode: false,
  vite:config     fs: { strict: true, allow: [Array], deny: [Array] }
  vite:config   },
  vite:config   preview: {
  vite:config     port: undefined,
  vite:config     strictPort: undefined,
  vite:config     host: undefined,
  vite:config     https: undefined,
  vite:config     open: undefined,
  vite:config     proxy: undefined,
  vite:config     cors: undefined,
  vite:config     headers: undefined
  vite:config   },
  vite:config   env: { BASE_URL: '/', MODE: 'production', DEV: false, PROD: true },
  vite:config   assetsInclude: [Function: assetsInclude],
  vite:config   logger: {
  vite:config     hasWarned: false,
  vite:config     info: [Function: info],
  vite:config     warn: [Function: warn],
  vite:config     warnOnce: [Function: warnOnce],
  vite:config     error: [Function: error],
  vite:config     clearScreen: [Function: clearScreen],
  vite:config     hasErrorLogged: [Function: hasErrorLogged]
  vite:config   },
  vite:config   packageCache: Map(0) { set: [Function (anonymous)] },
  vite:config   createResolver: [Function: createResolver],
  vite:config   worker: {
  vite:config     format: 'iife',
  vite:config     plugins: [
  vite:config       'vite:build-metadata',
  vite:config       'vite:pre-alias',
  vite:config       'alias',
  vite:config       'vite:modulepreload-polyfill',
  vite:config       'vite:resolve',
  vite:config       'vite:html-inline-proxy',
  vite:config       'vite:css',
  vite:config       'vite:esbuild',
  vite:config       'vite:json',
  vite:config       'vite:wasm-helper',
  vite:config       'vite:worker',
  vite:config       'vite:asset',
  vite:config       'vite:wasm-fallback',
  vite:config       'vite:define',
  vite:config       'vite:css-post',
  vite:config       'vite:build-html',
  vite:config       'vite:worker-import-meta-url',
  vite:config       'vite:asset-import-meta-url',
  vite:config       'vite:force-systemjs-wrap-complete',
  vite:config       'vite:watch-package-data',
  vite:config       'commonjs',
  vite:config       'vite:data-uri',
  vite:config       'vite:dynamic-import-vars',
  vite:config       'vite:import-glob',
  vite:config       'vite:build-import-analysis',
  vite:config       'vite:esbuild-transpile',
  vite:config       'vite:terser',
  vite:config       'vite:load-fallback'
  vite:config     ],
  vite:config     rollupOptions: {},
  vite:config     getSortedPlugins: [Function: getSortedPlugins],
  vite:config     getSortedPluginHooks: [Function: getSortedPluginHooks]
  vite:config   },
  vite:config   appType: 'spa',
  vite:config   experimental: { importGlobRestoreExtension: false, hmrPartialAccept: false },
  vite:config   getSortedPlugins: [Function: getSortedPlugins],
  vite:config   getSortedPluginHooks: [Function: getSortedPluginHooks]
  vite:config } +34ms
vite v4.0.0 building for production...
transforming (20) node_modules/.pnpm/@vue+devtools-api@6.4.5/node_modules/@vue/devtools-api/lib/esm/env.js  vite:resolve 2.10ms ./base.css -> /Users/yutengjing/code/vite-importmap/src/assets/base.css +0ms
✓ 48 modules transformed.
dist/assets/logo-da9b9095.svg        0.31 kB
dist/index.html                      0.87 kB
dist/assets/AboutView-4d995ba2.css   0.09 kB │ gzip:  0.10 kB
dist/assets/index-b9365240.css       4.18 kB │ gzip:  1.31 kB
dist/assets/AboutView-289b69fc.js    0.23 kB │ gzip:  0.20 kB
dist/assets/index-45b62779.js       84.35 kB │ gzip: 33.17 kB

Validations

@tjx666 tjx666 changed the title vite should not change importmap position in index.html **[Hard Issue]** vite should not change importmap position in index.html Dec 10, 2022
@tjx666 tjx666 changed the title **[Hard Issue]** vite should not change importmap position in index.html [Hard Issue] vite should not change importmap position in index.html Dec 10, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jan 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant