【问题标题】:Exclude specific JS file from Webpack transpilation, but include in bundle从 Webpack 转译中排除特定的 JS 文件,但包含在包中
【发布时间】:2021-02-16 05:57:21
【问题描述】:

我有一个非常大的 JS 文件 pleaseExcludeMe.js,它已经被缩小和转译,包含在我的 vue 项目中,它使用默认的 webpack 设置。

我想从 Webpack 转译/转换中排除该文件,但显然需要在包中

该文件由Rooms.vue 导入。

这是我的项目结构:

root
  src/
    views/
      rooms/
        Rooms.vue
        pleaseExcludeMe.js  
  package.json

在我的vue.config.js 中,我已经尝试过了:

configureWebpack: {
    module: {
        rules: [
            {
                test: /pleaseExcludeMe/,
                loader: 'null-loader', // also tried 'dumb-loader'
                exclude: /pleaseExcludeMe/, // this seems to exclude the file from the bundle
            },
        ],
    },
},

如何排除该特定文件?

【问题讨论】:

    标签: webpack vue-cli babel-loader


    【解决方案1】:

    我想通了:

    const path = require('path');
    
    // ...
    rules: [
      test: /\.js$/,
      exclude: [
        path.resolve(__dirname, 'src/views/rooms/pleaseExcludeMe.js'),
      ],
    ]
    

    【讨论】:

      猜你喜欢
      • 2018-12-22
      • 2021-07-03
      • 2019-01-06
      • 2020-07-22
      • 2017-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-22
      相关资源
      最近更新 更多