简体   繁体   English

使Webpack无需处理即可将文件从src移至dest

[英]Make webpack move files from src to dest without processing it

I have some sites running with JSF and some vanilla ES6 that is being processed with webpack (Running 4.6). 我有一些运行JSF的站点和一些正在用webpack处理的香草ES6(运行4.6)。

The problem is that webpack adds something to my jsf.js file when it moves the file to my dest folder, and doesn't work with how JSF needs to be run. 问题是,当webpack将文件移动到我的dest文件夹时,它会将一些内容添加到我的jsf.js文件中,并且与需要运行JSF的方式不兼容。

Setup: There is the jsf.js and the vanilla ES6 files in a src folder. 设置:src文件夹中有jsf.js和普通ES6文件。 I then use webpack to process and move the bundle and the jsf.js file to a dest folder. 然后,我使用webpack处理并将包和jsf.js文件移动到dest文件夹。

The JSF.js file is already minimized in the src folder and cannot be uglified so I have added exclude on uglify: JSF.js文件已在src文件夹中最小化,无法被丑化,因此我在uglify上添加了exclude:

 optimization: {
    minimizer: [
      new UglifyJsPlugin({
        exclude: /(jsf.js)/,
      })
    ]
  }

The jsf.js also has its own entry btw. jsf.js也有其自己的条目btw。

So my question is, how do I make webpack only move the jsf.js and add nothing to it? 所以我的问题是,如何使webpack 移动jsf.js而不添加任何内容? There must be some kind of exclude that I am missing here. 我在这里一定缺少某种排除。 I use no plugins other than uglify. 除了uglify外,我不使用任何插件。

If you just want copy jsf.js to dist directory. 如果只想将jsf.js复制到dist目录。 you should try copy-webpack-plugin , not give it its own entry. 您应该尝试copy-webpack-plugin ,而不要给它自己的条目。

install it throught npm: 通过npm安装它:

npm i -D copy-webpack-plugin

require it in webpack.config.js 在webpack.config.js中要求它

const CopyWebpackPlugin = require('copy-webpack-plugin')

add to plugins's array 添加到插件的数组

[
  new CopyWebpackPlugin([
    { from: 'path/to/jsf.js', to: 'dist/' }
  ])
]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM