如何在 Vue.js 中排除文件(例如配置文件)?

use*_*525 5 webpack vue.js

我试过了:

chainWebpack: config => {
    config.merge({
        module: {
            rules: [{
                test: /\.jsx?$/,
                exclude: {
                    exclude: [path.resolve(__dirname, "public/my-config.js")]
                }
            }]
        }
    })
}
Run Code Online (Sandbox Code Playgroud)

或者

config.module.rule('js')
  .exclude({
    exclude: path.resolve(__dirname, "public/my-config.js")
  })
Run Code Online (Sandbox Code Playgroud)

但这不起作用。

我想public/my-config.js使用 中的脚本标签导入pages/index.html或仅导入import { config1, config2 } from '../public/my-config'.

虽然我可以externals在 webpack 中不包含模块,但它对于 Vue.js 来说不太直观。

我必须将其my-config.js提供给dist/才能对其进行编辑。

use*_*525 3

参考:

我在我的 中写的vue.config.js

const path = require("path");

module.exports = {
    baseUrl: ".",
    chainWebpack: config => {
        config.plugin('copy').tap((args) => [[
              {
                from: '/path/to/my_project/public',
                to: '/path/to/my_project/dist',
                toType: 'dir',
                ignore: [
                  'index.html',
                  '.DS_Store',
                  'config.data.js'
                ]
              }
          ]]
        );
    }
}
Run Code Online (Sandbox Code Playgroud)

$ vue inspect > output.js然后我检查了output.js文件中使用了哪些参数,而该config.plugin('copy')参数恰好是new CopyWebpackPlugin.