我想为我使用 vue cli 3 创建的网页设置标题,因此查看了public/index.html. 在那里,我发现<title><%= htmlWebpackPlugin.options.title %></title>.
htmlWebpackPlugin.options.titlevue cli 3 项目中如何设置和修改?
我已经使用 @vue/cli-service 4.2 创建了 vue 和电子应用程序,因为我面临着可选链接的问题。
我不能用?用于验证条件,如 (@babel/plugin-proposal-optional-chaining)
例如。a?.b?.c 这意味着它检查天气 a 是否存在然后检查 b 否则返回 false 与 angular 中的模板表达式相同。
任何人都知道如何在 vuejs 中配置可选链。
我相信该npm run serve命令默认为 js 使用 sourcemap,但似乎不是因为我总是看到vue.runtime.esm.js:619.
我在根级项目中创建了一个 vue.config.js 文件。
我尝试两件事:
module.exports = {
configureWebpack: config => {
config.devtool = 'source-map'
}
}
Run Code Online (Sandbox Code Playgroud)
和:
module.exports = {
configureWebpack: {
devtool: 'source-map'
}
}
Run Code Online (Sandbox Code Playgroud)
它们都不起作用。我仍然坚持vue.runtime.esm.js:619哪个没用。
有谁知道如何真正使用 vue-cli 4 激活源映射?
我想生产代码不精缩在dist/与@vue/cli 4.1.2
1?第一次尝试设置 vue.config.js
module.exports = {
chainWebpack: config => {
config.optimization.minimize(false)
}
}
Run Code Online (Sandbox Code Playgroud)
然后其他部分正常,但内联脚本仍然被缩小。
var Appvue_type_template_id_7a951895_render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{attrs:{"id":"app"}},[_c('img',{attrs:{"alt":"Vue logo","src":__webpack_require__("cf05")}}),_c('HelloWorld',{attrs:{"msg":"Welcome to Your Vue.js App"}})],1)}
Run Code Online (Sandbox Code Playgroud)
2?第二次尝试
使用开发模式 vue-cli-service build --mode development
但代码格式是 eval(...)
vue 有这个选项publicPath,它允许一个应用程序部署在子路径上:foobar.com/my-path,使链接和每个资产都可以通过它访问。
从性能的角度来看,我想在我的应用程序资产上启用 CDN。如何将 URL 专门用于资产(而不是超链接)?
例子:
./my-path/assets/app.js应该变成https://my-staging-cdn.com/my-path/assets/app.js
./my-path/url-2.html应该保持不变
下面的配置允许我设置路径和资产目录,但无法弄清楚如何为资产设置cdn URL
module.exports = {
publicPath: ‘/my-path/‘,
assetsDir: 'assets'
}
Run Code Online (Sandbox Code Playgroud)
不能做:
publicPath: process.env.NODE_ENV === 'production' ? 'https://my-staging-cdn.com/my-path' : '/my-path/',因为它也会更改应用程序链接中的 URL。
虽然我显然不是 webpack 专家,但我通常会弄清楚/找出我需要修改什么才能实现我所需要的。然而,我在这件事上浪费了一天多的时间,尽管它看起来相当简单:
我想index.html在构建后通过从文件夹中复制它来将其添加到构建中。
我尝试将其添加到configureWebpack, 中vue.config.js:
plugins: [
new CopyPlugin([{
from: 'deploy',
to: '/',
force: true,
copyUnmodified: true
}])
]
Run Code Online (Sandbox Code Playgroud)
(文件夹中唯一的文件deploy是这个index.html)。
我还尝试了各种版本的chainWebpack,大部分是从 github 讨论中挑选的,试图利用诸如html、move-index和 之类的插件copy。然而,我在 github 上找到的大部分内容都破坏了我的构建。
即使是简单的尝试,我只是尝试点击,控制台似乎不起作用:
chainWebpack: config => {
config
.plugin('html')
.tap(args => {
console.log(args);
return args;
});
},
Run Code Online (Sandbox Code Playgroud)
输出:
Building for production as library (commonjs,umd,umd-min)...[]
ERROR TypeError: Cannot read property '__expression' of undefined`
...
at module.exports.toConfig (D:\sgn\www\_g\berwow\BERWoW\Client\RecommenderV2\node_modules\webpack-chain\src\Config.js:129:40)
Run Code Online (Sandbox Code Playgroud)
到目前为止我想到的: …
如何在动态路由导入中禁用rel="prefetch"?
我正在使用 @vue/cli 4.3.1 和 Webpack 4.43.0,尝试禁用预取:
在route.js中
const Registration = () => import( /* webpackPrefetch: false */
/* webpackChunkName: "registration" */ '../modules/Popup/Registration.vue')
Run Code Online (Sandbox Code Playgroud)
尝试在 vue.config.js 中配置,但没有帮助
chainWebpack: config => {
config.plugins.delete('prefetch')
config.plugins.delete('prefetch-index') // or
config.plugins.delete('preload')
}
Run Code Online (Sandbox Code Playgroud)
但无论如何都有
<link rel="prefetch" ....>
Run Code Online (Sandbox Code Playgroud) 当我尝试 vue add i18n 时,我正在运行此错误:
Invoking generator for vue-cli-plugin-i18n...
ERROR Error: You cannot call "get" on a collection with no paths. Instead, check the "length" property first to verify at least 1 path exists.
Error: You cannot call "get" on a collection with no paths. Instead, check the "length" property first to verify at least 1 path exists.
at Collection.get (/usr/local/lib/node_modules/@vue/cli/node_modules/jscodeshift/src/Collection.js:213:13)
at injectOptions (/usr/local/lib/node_modules/@vue/cli/lib/util/codemods/injectOptions.js:15:6)
at runTransformation (/usr/local/lib/node_modules/@vue/cli/node_modules/vue-codemod/dist/src/run-transformation.js:61:17)
at Object.keys.forEach.file (/usr/local/lib/node_modules/@vue/cli/lib/Generator.js:290:23)
at Array.forEach (<anonymous>)
at Generator.resolveFiles (/usr/local/lib/node_modules/@vue/cli/lib/Generator.js:276:24)
at process._tickCallback (internal/process/next_tick.js:68:7)
Run Code Online (Sandbox Code Playgroud)
vue …
我正在尝试创建 Vue.js 3 SSR 应用程序(包括 ts、@vue/cli、babel)。我使用 Nodejs + Express 作为后端。SSR 工作正常(我从服务器正确渲染了 html),但在客户端水合作用期间发生错误。我的客户端构建似乎不包含组件的模板,因为我在浏览器中收到这些错误
\nVue warn]: Component is missing template or render function. \n at <App> \n at <App>\n\nVue warn]: Hydration node mismatch:\n- Client vnode: Symbol(Comment) \n- Server rendered DOM: <div class=\xe2\x80\x8b"hello-world">\xe2\x80\x8bhello\xe2\x80\x8b</div>\xe2\x80\x8b \n at <App> \n at <App>\n\nruntime-core.cjs.js:2942 Hydration completed but contains mismatches.\nRun Code Online (Sandbox Code Playgroud)\n我发现当我用渲染函数替换模板时错误消失了,但它再次出现在子组件上(为简单起见,HelloWorld没有子组件)。
\n这是我的 github 存储库,我在其中重现了我的问题。
index.html
Vue warn]: Component is missing template or render function. \n at <App> \n at <App>\n\nVue warn]: Hydration node …Run Code Online (Sandbox Code Playgroud) 我在由 Vue CLI 4 提供支持的 VueJS 应用程序中创建了两个插件,但是当我尝试在我的页面中使用它时,只有一个可以工作
| plugins
|-- axios.vue
|-- authentication.vue
Run Code Online (Sandbox Code Playgroud)
axios.vue
| plugins
|-- axios.vue
|-- authentication.vue
Run Code Online (Sandbox Code Playgroud)
身份验证.vue
import Vue from "vue";
Plugin.install = function(Vue) {
Vue.prototype.$myName = "Dean Armada";
};
Vue.use(Plugin);
export default Plugin;
Run Code Online (Sandbox Code Playgroud)
主文件
import Vue from "vue";
Plugin.install = function(Vue) {
Vue.prototype.$name = "Chris Guinto";
};
Vue.use(Plugin);
export default Plugin;
Run Code Online (Sandbox Code Playgroud)
说明.vue
import axios from "./plugins/axios.js";
import authentication from "./plugins/authentication.js";
Vue.use(axios);
Vue.use(authentication);
Run Code Online (Sandbox Code Playgroud)
console.log(this.$name)未定义Vue.use(axios)了console.log(this.$name)将努力使其输出将是“克里斯Guinto”,另一种是不明确的,因为axios插件未激活那么我怎样才能让它们同时工作呢?
vue-cli-4 ×10
vue.js ×6
vue-cli ×4
vue-cli-3 ×3
javascript ×2
vuejs3 ×2
webpack ×2
build ×1
electron ×1
node.js ×1
prefetch ×1
source-maps ×1
typescript ×1
vue-i18n ×1
vuejs2 ×1