在 Vue Client 3 中使用 webpack 插件 [英] Using a webpack plugin with Vue Client 3
问题描述
我想使用 vue-cli 在 Vue 中使用 webpack 插件,但我不想安装 webpack,因为 Vue 会处理这个...
I want to use a webpack plugin in Vue using vue-cli but I don't want to install webpack, because Vue handles this...
使用 this 示例,我尝试使用
Using this example, I try to use the Environment plugin from webpack.
module.exports = {
configureWebpack: {
plugins: [
new EnvironmentPlugin([
'HEROKU_RELEASE_VERSION']),
],
},
};
但是因为我们使用 vue-cli,我得到:
But because we use vue-cli, I get :
EnvironmentPlugin 未定义
EnvironmentPlugin is not defined
当我包含 webpack 要求时
When I include the webpack requirement
const webpack = require('webpack')
module.exports = {
configureWebpack: {
plugins: [
new webpack.EnvironmentPlugin([
'HEROKU_RELEASE_VERSION']),
],
},
};
我明白了:
Webpack 应该列在项目的依赖项中.运行 npm install ....
Webpack should be listed in the project's dependencies. run npm install ....
推荐答案
首先需要安装 webpack 作为依赖项.
First you need to install webpack as dependency.
npm i --save-dev webpack
然后将以下内容添加到您的 vue.config.js
.
After that add the following to your vue.config.js
.
const webpack = require('webpack')
module.exports = {
configureWebpack: {
plugins: [
new webpack.EnvironmentPlugin([
'HEROKU_RELEASE_VERSION',
]),
]
}
}
这篇关于在 Vue Client 3 中使用 webpack 插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!