如何在 Vue.js 中排除文件(例如配置文件)? [英] How do I exclude a file (eg config file) in Vue.js?

查看:178
本文介绍了如何在 Vue.js 中排除文件(例如配置文件)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过了:

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

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

但它不起作用.

我想在 pages/index.html 中使用 script 标签导入 public/my-config.js 或者只是 import { config1, config2 }来自'../public/my-config'.

I want to either import public/my-config.js with script tag in the pages/index.html or just import { config1, config2 } from '../public/my-config'.

虽然我可以使用 externals 在 webpack 中不包含模块,但它对 Vue.js 来说不是很直观.

I was able to use externals to not include a module in webpack though, but it's not quite intuitive with Vue.js.

我必须在 dist/ 中提供 my-config.js 以便可以对其进行编辑.

I must have the my-config.js be available at dist/ so that it can be edited.

推荐答案

参考:https://github.com/vuejs/vue-cli/issues/2231#issuecomment-413441633

试试这个,更简单:

module.exports = {
  chainWebpack: config => {
    config.plugin('copy').tap(([options]) => {
      options[0].ignore.push('api/**/*')
      return [options]
    })
  }
}

这篇关于如何在 Vue.js 中排除文件(例如配置文件)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆