Giter Site home page Giter Site logo

Comments (22)

PachVerb avatar PachVerb commented on June 1, 2024 4

yes, so i need to ignore public/index.html, but globOptions.ignore not working

it's work for me. just add globalOptions-ignore [**/*.html],

my webpack.common.js

  new webpack.DefinePlugin({
      BASE_URL: JSON.stringify('/'),
    }),
    new HtmlWebpackPlugin({
      // 指定模板,此插件仍然会创建文件
      title: 'Typescript + Vue',
      template: '/public/index.html', // 如果使用自己的模板需要另外引入favicon图标
      //   favicon: '../public/favicon.ico',
    }),

    new CopyPlugin({
      patterns: [
        {
          from: path.resolve(__dirname, '../public'),
          to: path.resolve(__dirname, '../dist'),
          toType: 'dir',
          globOptions: {
            dot: false, // 允许匹配以 . 开头的文件, 比如 .gitignore
            gitignore: false,
            ignore: ['.DS_Store', '**/index.html'],
          },
        },
      ],
    }),

NOTE: html-webpack-plugin, default Specifying the template will also output the html file to the build directory, should you also specify the final output filename

from copy-webpack-plugin.

alexander-akait avatar alexander-akait commented on June 1, 2024 2

Try to experiment, ignore is working, just with some limitations

from copy-webpack-plugin.

alexander-akait avatar alexander-akait commented on June 1, 2024 2

It means globby can't find directory

from copy-webpack-plugin.

alexander-akait avatar alexander-akait commented on June 1, 2024

Sorry, problem is not in the plugin, all options from globOptions passed to fast-glob, so if something is not ignored, it means fast-glob is not ignore it

from copy-webpack-plugin.

ruokid avatar ruokid commented on June 1, 2024

same issue

copy-webpack-plugin @5.x

new CopyPlugin(
  [
    {
      from: 'public',
      to: '/XXX/dist',
      toType: 'dir',
      ignore: [
        '.DS_Store',
        {
          glob: 'index.html',
          matchBase: false
        }
      ]
    }
  ]
)

copy-webpack-plugin @11.x (ignore option not working)

new CopyWebpackPlugin({
  patterns: [
    {
      from: 'public',
      to: /XXX/dist,
      toType: 'dir',
      globOptions: {
        ignore: [ '.DS_Store', 'index.html' ]
      }
    }
  ]
})

from copy-webpack-plugin.

alexander-akait avatar alexander-akait commented on June 1, 2024

Please use **/.DS_Store for nested, docs here https://github.com/mrmlnc/fast-glob#ignore

from copy-webpack-plugin.

ruokid avatar ruokid commented on June 1, 2024

hi @alexander-akait

when i use it to build

new CopyWebpackPlugin({
  patterns: [
    {
      from: 'public',
      to: /XXX/dist,
      toType: 'dir',
      globOptions: {
        ignore: [ 'index.html' ]
      }
    }
  ]
}),
new HtmlWebpackPlugin({
  filename: 'index.html',
  template: 'public/index.html',
  title: projectName
})

I got

ERROR in Conflict: Multiple assets emit different content to the same filename index.html

now, if i use this

new CopyWebpackPlugin({
  patterns: [
    {
      from: 'public',
      to: /XXX/dist,
      toType: 'dir',
      globOptions: {
        ignore: [ '**/index.html' ]
      }
    }
  ]
}),
new HtmlWebpackPlugin({
  filename: 'index.html',
  template: 'public/index.html',
  title: projectName
})

i got

ERROR in unable to locate '/XXX/public/**/*' glob

and this is my directory
image

from copy-webpack-plugin.

alexander-akait avatar alexander-akait commented on June 1, 2024

ERROR in Conflict: Multiple assets emit different content to the same filename index.html

It means you have multiple files with different content:

  1. You copy files with the same name in one directory (i.e. dir1/index.html and dir2/index.html => dist/index.html)
  2. You have html-webpack-plugin and copy index.html, the situation the same as above, just html-webpack-plugin creates index.html

from copy-webpack-plugin.

ruokid avatar ruokid commented on June 1, 2024

yes, so i need to ignore public/index.html, but globOptions.ignore not working

from copy-webpack-plugin.

N-You avatar N-You commented on June 1, 2024

hi @alexander-akait

when i use it to build

new CopyWebpackPlugin({
  patterns: [
    {
      from: 'public',
      to: /XXX/dist,
      toType: 'dir',
      globOptions: {
        ignore: [ 'index.html' ]
      }
    }
  ]
}),
new HtmlWebpackPlugin({
  filename: 'index.html',
  template: 'public/index.html',
  title: projectName
})

I got

ERROR in Conflict: Multiple assets emit different content to the same filename index.html

now, if i use this

new CopyWebpackPlugin({
  patterns: [
    {
      from: 'public',
      to: /XXX/dist,
      toType: 'dir',
      globOptions: {
        ignore: [ '**/index.html' ]
      }
    }
  ]
}),
new HtmlWebpackPlugin({
  filename: 'index.html',
  template: 'public/index.html',
  title: projectName
})

i got

ERROR in unable to locate '/XXX/public/**/*' glob

and this is my directory image

I had the same problem

from copy-webpack-plugin.

wkz2003 avatar wkz2003 commented on June 1, 2024

yes, so i need to ignore public/index.html, but globOptions.ignore not working

it's work for me. just add globalOptions-ignore [**/*.html],

my webpack.common.js

  new webpack.DefinePlugin({
      BASE_URL: JSON.stringify('/'),
    }),
    new HtmlWebpackPlugin({
      // 指定模板,此插件仍然会创建文件
      title: 'Typescript + Vue',
      template: '/public/index.html', // 如果使用自己的模板需要另外引入favicon图标
      //   favicon: '../public/favicon.ico',
    }),

    new CopyPlugin({
      patterns: [
        {
          from: path.resolve(__dirname, '../public'),
          to: path.resolve(__dirname, '../dist'),
          toType: 'dir',
          globOptions: {
            dot: false, // 允许匹配以 . 开头的文件, 比如 .gitignore
            gitignore: false,
            ignore: ['.DS_Store', '**/index.html'],
          },
        },
      ],
    }),

NOTE: html-webpack-plugin, default Specifying the template will also output the html file to the build directory, should you also specify the final output filename

兄弟我复制你的发现也不报错了,啥原理啊这是,我听着有点迷糊

from copy-webpack-plugin.

wkz2003 avatar wkz2003 commented on June 1, 2024

yes, so i need to ignore public/index.html, but globOptions.ignore not working

it's work for me. just add globalOptions-ignore [**/*.html],

my webpack.common.js

  new webpack.DefinePlugin({
      BASE_URL: JSON.stringify('/'),
    }),
    new HtmlWebpackPlugin({
      // 指定模板,此插件仍然会创建文件
      title: 'Typescript + Vue',
      template: '/public/index.html', // 如果使用自己的模板需要另外引入favicon图标
      //   favicon: '../public/favicon.ico',
    }),

    new CopyPlugin({
      patterns: [
        {
          from: path.resolve(__dirname, '../public'),
          to: path.resolve(__dirname, '../dist'),
          toType: 'dir',
          globOptions: {
            dot: false, // 允许匹配以 . 开头的文件, 比如 .gitignore
            gitignore: false,
            ignore: ['.DS_Store', '**/index.html'],
          },
        },
      ],
    }),

NOTE: html-webpack-plugin, default Specifying the template will also output the html file to the build directory, should you also specify the final output filename

刚看错了,还是报错啊兄弟

from copy-webpack-plugin.

rendall avatar rendall commented on June 1, 2024

I'm not sure I completely understand if this will help OP, but I wanted to ignore specific files in the from: directory (in my case, only ./static/index.html and not ./static/**/index.html. For people struggling with this like me, you might consider ditching globOptions and using filter instead. It's a predicate that takes the file's (absolute) path and returns a true or false to be copied or not.

This is how I got it to work:

patterns: [{ from: "./static", filter:(filepath) => {
    const ignorePaths = ['/static/index.html']
    const doCopy = ignorePaths.every(path => !filepath.endsWith(path))
     return doCopy;
} }]

For my case, since I am ignoring one file, a simple return !filePath.endsWith('/static/index.html') would be fine. In this code, you can add your filepath to ignorePaths and it will return false if the (absolute) filepath ends in any of the ignorePaths, true otherwise.

from copy-webpack-plugin.

wkz2003 avatar wkz2003 commented on June 1, 2024

I'm not sure I completely understand the OP, but I wanted to ignore specific files in the from: directory (in my case, only ./static/index.html and not ./static/**/index.html. For people struggling with this like me, you might consider ditching globOptions and using filter instead. It's a predicate that takes the file's (absolute) path and returns a true or false, whether you want it to be copied or not.

This is how I got it to work:

patterns: [{ from: "./static", filter:(filepath) => {
    const ignorePaths = ['/static/index.html']
    const doCopy = ignorePaths.every(path => !filepath.endsWith(path))
     return doCopy;
} }]

For my case, since I am ignoring one file, a simple return !filePath.endsWith('/static/index.html') would be fine. In this code, you can add your filepath to ignorePaths and it will return false if the (absolute) filepath ends in any of the ignorePaths, true otherwise.

I'm not sure I completely understand the OP, but I wanted to ignore specific files in the from: directory (in my case, only ./static/index.html and not ./static/**/index.html. For people struggling with this like me, you might consider ditching globOptions and using filter instead. It's a predicate that takes the file's (absolute) path and returns a true or false, whether you want it to be copied or not.

This is how I got it to work:

patterns: [{ from: "./static", filter:(filepath) => {
    const ignorePaths = ['/static/index.html']
    const doCopy = ignorePaths.every(path => !filepath.endsWith(path))
     return doCopy;
} }]

For my case, since I am ignoring one file, a simple return !filePath.endsWith('/static/index.html') would be fine. In this code, you can add your filepath to ignorePaths and it will return false if the (absolute) filepath ends in any of the ignorePaths, true otherwise.

oh! It's a good solution.The only shortcoming is I can't use cases like 'public/**.html',but I think I can use regex to fix that

from copy-webpack-plugin.

rendall avatar rendall commented on June 1, 2024

Definitely! Something like

return /public\/.*\.html$/.test(filepath)

from copy-webpack-plugin.

realmxu avatar realmxu commented on June 1, 2024
      ignore: ['.DS_Store', '**/index.html'],

globalOptions.ignore seems only work on alone '**/index.html' but i can use fliter option hahaha.

from copy-webpack-plugin.

Sober-1 avatar Sober-1 commented on June 1, 2024

hi @alexander-akait ,I encountered the same problem as above.
The plug-in version I use is 11.0.0.
image
image
I tried to copy the contents of the public folder under the root directory to the webpack packaged folder,
And ignore a.js, b.js, and index.html.
When I ignore only a.js and index.html, it works normally, but when I ignore b.js at the same time, an error will be reported.
image
Could you explain the reason? thank you!

from copy-webpack-plugin.

alexander-akait avatar alexander-akait commented on June 1, 2024

@Sober-1 hm, can you create reproducible test repo? it should work

from copy-webpack-plugin.

Sober-1 avatar Sober-1 commented on June 1, 2024

@alexander-akait
I also did a test on my Mac and the same problem occurred

from copy-webpack-plugin.

alexander-akait avatar alexander-akait commented on June 1, 2024

Do you have the public directory? If no (or if it will be created as a part of build) please try https://github.com/webpack-contrib/copy-webpack-plugin#noerroronmissing

from copy-webpack-plugin.

Sober-1 avatar Sober-1 commented on June 1, 2024

I used " noErrorOnMissing: true", Now the problem has been solved. thank you

from copy-webpack-plugin.

fsjohnhuang avatar fsjohnhuang commented on June 1, 2024

Change index.html to **/public/index.html would work as expect.

from copy-webpack-plugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.