Vue-cli: vuecli默认设置了publicpath,导致配置的__webpack_public_path__无效

Created on 27 Dec 2019  ·  3Comments  ·  Source: vuejs/vue-cli

Version

3.6.0

Environment info

System:
    OS: Windows 10
    CPU: (4) x64 Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
  Binaries:
    Node: 10.16.0 - C:\Program Files\nodejs\node.EXE     
    Yarn: Not Found
    npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: 44.18362.449.0
  npmPackages:
    @vue/babel-helper-vue-jsx-merge-props:  1.0.0        
    @vue/babel-plugin-transform-vue-jsx:  1.1.2
    @vue/babel-preset-app:  3.12.1
    @vue/babel-preset-jsx:  1.1.2
    @vue/babel-sugar-functional-vue:  1.1.2
    @vue/babel-sugar-inject-h:  1.1.2
    @vue/babel-sugar-v-model:  1.1.2
    @vue/babel-sugar-v-on:  1.1.2
    @vue/cli-overlay:  3.12.1
    @vue/cli-plugin-babel: 3.6.0 => 3.6.0
    @vue/cli-plugin-eslint: ^3.9.1 => 3.12.1
    @vue/cli-plugin-unit-jest: 3.6.3 => 3.6.3
    @vue/cli-service: 3.6.0 => 3.6.0
    @vue/cli-shared-utils:  3.12.1
    @vue/component-compiler-utils:  2.6.0 (3.0.2)
    @vue/preload-webpack-plugin:  1.1.1
    @vue/test-utils: 1.0.0-beta.29 => 1.0.0-beta.29
    @vue/web-component-wrapper:  1.2.0
    babel-helper-vue-jsx-merge-props:  2.0.3
    eslint-plugin-vue: 5.2.2 => 5.2.2 (4.7.1)
    jest-serializer-vue:  2.0.2
    vue: 2.6.10 => 2.6.10
    vue-eslint-parser:  2.0.3 (5.0.0)
    vue-hot-reload-api:  2.3.4
    vue-jest:  3.0.5
    vue-loader:  15.7.2
    vue-router: 3.0.6 => 3.0.6
    vue-style-loader:  4.1.2
    vue-template-compiler: 2.6.10 => 2.6.10
    vue-template-es2015-compiler:  1.9.1
    vuex: 3.1.0 => 3.1.0

Steps to reproduce

按照webpack文档https://webpack.docschina.org/configuration/output/#output-publicpath,“在编译时(compile time)无法知道输出文件的 publicPath 的情况下,可以留空,然后在入口文件(entry file)处使用自由变量(free variable) __webpack_public_path__,以便在运行时(runtime)进行动态设置”
image

我的vue多页项目想让不同页面打包的publicPath不同,所以按照文档在不同的入口文件配置了指定__webpack_public_path__,但是vuecli默认有publicPath,所以__webpack_public_path__不生效

What is expected?

打包时__webpack_public_path__按照webpack文档说明一样生效

What is actually happening?

__webpack_public_path__设置不生效

All 3 comments

publicPath 设置为 '' 就好了

@sodatea 即使把 publicPath 设置为 ''<style> 标签内的路径依然不支持 __webpack_public_path__,有什么其他方式可以在运行时修改 vue-cli 的 publicPath 这个配置吗

publicPath 设置为 '' 就好了

写死也不起作用

Was this page helpful?
0 / 5 - 0 ratings