vuejs / vue-cli

🛠️ webpack-based tooling for Vue.js Development
https://cli.vuejs.org/
MIT License
29.76k stars 6.33k forks source link

Wrong url for safari-nomodule-fix if publicPath is absolute url (V5) #6594

Open 7iomka opened 3 years ago

7iomka commented 3 years ago

Version

5.0.0-beta.2

Environment info

  System:
    OS: macOS 10.15.7
    CPU: (6) x64 Intel(R) Core(TM) i5-8500B CPU @ 3.00GHz
  Binaries:
    Node: 12.16.3 - /usr/local/bin/node
    Yarn: 1.17.3 - ~/.npm-global/bin/yarn
    npm: 6.14.8 - ~/.npm-global/bin/npm
  Browsers:
    Chrome: 92.0.4515.93
    Edge: Not Found
    Firefox: 90.0
    Safari: 14.1
  npmPackages:
    @vue/babel-helper-vue-jsx-merge-props:  1.2.1 
    @vue/babel-helper-vue-transform-on:  1.0.2 
    @vue/babel-plugin-jsx:  1.0.6 
    @vue/babel-plugin-transform-vue-jsx:  1.2.1 
    @vue/babel-preset-app:  5.0.0-beta.2 
    @vue/babel-preset-jsx:  1.2.4 
    @vue/babel-sugar-composition-api-inject-h:  1.2.1 
    @vue/babel-sugar-composition-api-render-instance:  1.2.4 
    @vue/babel-sugar-functional-vue:  1.2.2 
    @vue/babel-sugar-inject-h:  1.2.2 
    @vue/babel-sugar-v-model:  1.2.3 
    @vue/babel-sugar-v-on:  1.2.3 
    @vue/cli-overlay:  5.0.0-beta.2 
    @vue/cli-plugin-babel: ~5.0.0-beta.2 => 5.0.0-beta.2 
    @vue/cli-plugin-eslint: ^5.0.0-beta.2 => 5.0.0-beta.2 
    @vue/cli-plugin-router: ^5.0.0-beta.2 => 5.0.0-beta.2 
    @vue/cli-plugin-vuex: ^5.0.0-beta.2 => 5.0.0-beta.2 
    @vue/cli-service: ~5.0.0-beta.2 => 5.0.0-beta.2 
    @vue/cli-shared-utils:  5.0.0-beta.2 
    @vue/compiler-core:  3.1.5 
    @vue/compiler-dom:  3.1.5 
    @vue/compiler-sfc:  3.1.5 
    @vue/compiler-ssr:  3.1.5 
    @vue/component-compiler-utils:  3.2.2 
    @vue/eslint-config-prettier: ^6.0.0 => 6.0.0 
    @vue/shared:  3.1.5 
    @vue/web-component-wrapper:  1.3.0 
    eslint-plugin-vue: ^7.14.0 => 7.14.0 
    vue: ^2.6.11 => 2.6.14 
    vue-cli-plugin-style-resources-loader: ~0.1.5 => 0.1.5 
    vue-eslint-parser:  7.9.0 
    vue-gettext: ^2.1.12 => 2.1.12 
    vue-hot-reload-api:  2.3.4 
    vue-loader:  16.3.1 (15.9.7)
    vue-router: ^3.2.0 => 3.5.2 
    vue-style-loader:  4.1.3 
    vue-template-compiler: ^2.6.14 => 2.6.14 
    vue-template-es2015-compiler:  1.9.1 
    vuex: ^3.4.0 => 3.6.2 
  npmGlobalPackages:
    @vue/cli: Not Found

Steps to reproduce

publicPath:
    process.env.NODE_ENV === 'production'
      ? 'http://localhost:8000/static/frontend'
      : '/static/frontend',

What is expected?

Script publicPath is the same and is correct

<script src="http://localhost:8000/static/frontend/js/safari-nomodule-fix.js" type="module"></script>

What is actually happening?

Script publicPath is wrong, 2nd slash after http is omitted

<script src="http:/localhost:8000/static/frontend/js/safari-nomodule-fix.js" type="module"></script>

Why? How to pass absolute url for production? (I have all static files hosted on CDN on another domain)

luming747 commented 3 years ago

me too

simon-yxl commented 2 years ago

me too

lyphol commented 2 years ago

Has this problem not been solved yet?

The cause is: path.join('http://localhost:8080/cdn/','js/safari-nomodule-fix.js') // http:/localhost:8080/cdn/js/safari-nomodule-fix.js the result lost a '/'

7iomka commented 2 years ago

lol) looks like the project has been abandoned if such a critical issue is not fixed

RekingZhang commented 2 years ago
 configureWebpack: (config) => {
        const SafariNomoduleFixPlugin = config.plugins.find(
            (plugin) => plugin?.constructor?.name === 'SafariNomoduleFixPlugin'
        );
        if (SafariNomoduleFixPlugin) {
            SafariNomoduleFixPlugin.unsafeInline = true;
        }
}
Kyoloro commented 2 years ago

7232

yilihjy commented 2 years ago

In my project, I use https://github.com/vuejs/vue-cli/pull/7247 to solve this issue.

ceynri commented 1 year ago

+1

vue.config.js:

{
  publicPath: '//mydomain.com/xxx/',
}

output:

<script src="/mydomain.com/xxx/js/safari-nomodule-fix.js" type="module"></script>

expect:

<script src="//mydomain.com/xxx/js/safari-nomodule-fix.js" type="module"></script>

seem #7247 can resolve this issue?