虽然我显然不是Webpack专家,但我通常会弄清楚/发现需要修改哪些内容才能实现所需的功能。但是,即使看起来很简单,我在这一天也损失了不止一天:
我想在构建后通过从文件夹复制将index.html
添加到构建中。
我尝试将其添加到configureWebpack
中的vue.config.js
:
plugins: [
new CopyPlugin([{
from: 'deploy',
to: '/',
force: true,
copyUnmodified: true
}])
]
([deploy
文件夹中的唯一文件是此index.html
)。
[我还尝试了chainWebpack
的各种版本,主要是从github讨论中选取的,试图利用html
,move-index
和copy
之类的插件。但是,我在github上发现的大多数内容都对我不利。
甚至不是简单的尝试,在这里我只是尝试点按和控制台似乎都不起作用:
chainWebpack: config => {
config
.plugin('html')
.tap(args => {
console.log(args);
return args;
});
},
输出:
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)
我到目前为止所发现的:
.html
文件例外。move-index
和html
),可能会干扰我的复制。我还没有弄清楚如何将我的更改推送到队列的后面。[我也尝试过使用test.html
,并且我还尝试在文件.txt
上放置一个不同的扩展名,并在复制时将其覆盖并复制回.html
。大多数情况下,我都会遇到错误。
[是否有一种相对直接的方法可以利用vue-cli-serve
的build
命令并将一个index.html
复制到该文件夹中?
我正在使用的构建命令是:
vue-cli-service build --target lib --name SomeName --inline-css --inline-vue src/main.ts
[请注意,这是一个--target lib
构建,它不会将index.html
输出到dist
文件夹中,而是输出到demo.html
。因此,我建议您针对--target lib
构建测试任何解决方案,因为它的输出显然不同于正常构建。
这里是vue inspect
的输出:https://jsfiddle.net/websiter/rkh5ecvd/embedded/js/dark/#JavaScript这是我的vue.config.js
的当前内容:https://jsfiddle.net/websiter/fou3y4zc/embedded/js/dark/#JavaScript,其中configWebpack
和chainWebpack
试图解决/窥视上述问题。
我正在将@vue/cli 4.2.3
和vue 2.6.11
与webpack 4.42.1
一起使用
我想出了一种解决方法,只需运行npm i copyfiles -D
并将此位添加到build
脚本中:
&& copyfiles -f ./deploy/* dist/Recommender
这不是对该问题的正确答案,这是解决之道。但是有效:)。