admin管理员组

文章数量:1417051

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.

本文标签: