最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using CopyWebpackPlugin how can I copy files out of node_modules into a folder without it creating a node_modules f

programmeradmin0浏览0评论

I'm trying to use CopyWebpackPlugin to copy some files out of my node_modules folder and into my build folder.

new CopyWebpackPlugin([
  { from: 'node_modules/accounting/**', to: 'vendor/npm/' },
  { from: 'node_modules/angular/**', to: 'vendor/npm/' },

I would expect this to output to my build folder /build/vendor/npm/accounting and build/vendor/npm/angular respectively, but instead a node_modules folder is created - the files are actually outputted to build/vendor/npm/node_modules/accounting.

How can I prevent the node_modules folder being created and get my expected output?

I'm trying to use CopyWebpackPlugin to copy some files out of my node_modules folder and into my build folder.

new CopyWebpackPlugin([
  { from: 'node_modules/accounting/**', to: 'vendor/npm/' },
  { from: 'node_modules/angular/**', to: 'vendor/npm/' },

I would expect this to output to my build folder /build/vendor/npm/accounting and build/vendor/npm/angular respectively, but instead a node_modules folder is created - the files are actually outputted to build/vendor/npm/node_modules/accounting.

How can I prevent the node_modules folder being created and get my expected output?

Share Improve this question edited Oct 2, 2018 at 15:12 CD-jS asked Oct 2, 2018 at 14:11 CD-jSCD-jS 1,1191 gold badge15 silver badges33 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

For future reference, the actual correct answer is that I needed context -

{ from: 'accounting/**', to: 'vendor/npm', context: 'node_modules' }

Include a leading / to use the absolute output path

new CopyWebpackPlugin([
  { from: 'node_modules/accounting/**', to: '/build/vendor/npm/accounting' },
  { from: 'node_modules/angular/**', to: '/build/vendor/npm/angular' },
],

Because you're using a glob in your from path, the to path is relative to the resolved from paths. Github docs.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论