CopyWebpackPlugin usage question
-
Hi! Can’t copy robots.txt on quasar build with CopyWebpackPlugin. I’ve just copy-paste from there, but there is an error:
app:webpack Extending SPA Webpack config +493ms (node:15489) UnhandledPromiseRejectionWarning: ValidationError: Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema. - options[0] misses the property 'patterns'. Should be: [non-empty string | object { from, to?, context?, globOptions?, toType?, force?, flatten?, transform?, cacheTransform?, transformPath?, noErrorOnMissing? }, ...] (should not have fewer than 1 item)
What I’m doing wrong? Help pls!
-
Hi,
Did you find the solution?
I have the same problem and I still managed to find the solution.
Thank you in advance. -
This might be because you’ve updated to a newer version. What solved it for me was changing from:
const CleanWebpackPlugin = require('clean-webpack-plugin'); ... plugins: [ new CleanWebpackPlugin(), new MiniCssExtractPlugin({ filename: "css/[name].bundle.css", chunkFilename: "css/[name][id].bundle.css" }), new CopyWebpackPlugin([{ from: path.resolve(__dirname, '../src/static') }]) ],
to: const { CleanWebpackPlugin } = require('clean-webpack-plugin'); ... plugins: [ new CopyWebpackPlugin({ patterns: [ {from: path.resolve(__dirname, '../src/static')} ] }) ],
-
install robotstxt-webpack-plugin.js
npm i robotstxt-webpack-plugin
in your quasar.conf.js
importconst RobotstxtPlugin = require("robotstxt-webpack-plugin"); const options = { filePath: "/robots.txt", policy: [ { userAgent: "*", Allow: 'All', crawlDelay: 30 } ], sitemap: "https://example.com/sitemap.xml", host: "https://example.com" };
build: { scopeHoisting: true, vueRouterMode: "history", // available values: 'hash', 'history' showProgress: true, gzip: false, analyze: false, // Options below are automatically set depending on the env, set them if you want to override // preloadChunks: false, extractCSS: true, // https://quasar.dev/quasar-cli/cli-documentation/handling-webpack extendWebpack(cfg) { cfg.plugins.push( new RobotstxtPlugin(options) ); } },