Comments (22)
yes, so i need to ignore
public/index.html
, butglobOptions.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.
Try to experiment, ignore is working, just with some limitations
from copy-webpack-plugin.
It means globby can't find directory
from copy-webpack-plugin.
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.
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.
Please use **/.DS_Store
for nested, docs here https://github.com/mrmlnc/fast-glob#ignore
from copy-webpack-plugin.
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
from copy-webpack-plugin.
ERROR in Conflict: Multiple assets emit different content to the same filename index.html
It means you have multiple files with different content:
- You copy files with the same name in one directory (i.e.
dir1/index.html
anddir2/index.html
=>dist/index.html
) - You have
html-webpack-plugin
and copyindex.html
, the situation the same as above, justhtml-webpack-plugin
createsindex.html
from copy-webpack-plugin.
yes, so i need to ignore public/index.html
, but globOptions.ignore
not working
from copy-webpack-plugin.
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
I had the same problem
from copy-webpack-plugin.
yes, so i need to ignore
public/index.html
, butglobOptions.ignore
not workingit'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.
yes, so i need to ignore
public/index.html
, butglobOptions.ignore
not workingit'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.
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.
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 ditchingglobOptions
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 toignorePaths
and it will return false if the (absolute) filepath ends in any of theignorePaths
, 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 ditchingglobOptions
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 toignorePaths
and it will return false if the (absolute) filepath ends in any of theignorePaths
, 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.
Definitely! Something like
return /public\/.*\.html$/.test(filepath)
from copy-webpack-plugin.
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.
hi @alexander-akait ,I encountered the same problem as above.
The plug-in version I use is 11.0.0.
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.
Could you explain the reason? thank you!
from copy-webpack-plugin.
@Sober-1 hm, can you create reproducible test repo? it should work
from copy-webpack-plugin.
@alexander-akait
I also did a test on my Mac and the same problem occurred
from copy-webpack-plugin.
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.
I used " noErrorOnMissing: true", Now the problem has been solved. thank you
from copy-webpack-plugin.
Change index.html
to **/public/index.html
would work as expect.
from copy-webpack-plugin.
Related Issues (20)
- Getting security issues in underlying tar library HOT 1
- node version no right and no warn HOT 2
- Plugin causes build failure on netlify HOT 1
- Use the latest version to set the info field The file is still packed and compressed HOT 2
- `HookWebpackError: WebAssembly.instantiate(): Out of memory: wasm memory` in version 10.2.4 when nested in a `osc` build pipeline HOT 2
- Copy files from "src/*.jpg" to "dist/" root. HOT 5
- HookWebpackError: Must use import to load ES Module HOT 3
- copy file permissions HOT 3
- Cache directory can't be configured HOT 7
- Who would use this to make nuxt2 use cesium 1.111.0? HOT 1
- Cannot use a folder named `node_modules` for the `to` path HOT 2
- Lack of useful use case HOT 2
- Resolve Snyk vulnerability warning on 9th Jan from 'serialize-javascript' package HOT 2
- ERROR in directoryPaths.map is not a function with v12.x HOT 5
- The new asyncMemoize function should memoize the original promise HOT 4
- (BROKEN ON MACOS) Binary files lose executable permissions after copy. HOT 5
- HookWebpackError: Unexpected token '??=' HOT 1
- getCache is not a function HOT 1
- No default export found in imported module "copy-webpack-plugin" in webpack.config.ts HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from copy-webpack-plugin.