Search code examples
webpackvue-clibabel-loader

Exclude specific JS file from Webpack transpilation, but include in bundle


I have a very large JS file pleaseExcludeMe.js that is already minified and transpiled included in my vue project, which is using the default webpack setup.

I want to exclude that file from Webpack transpilation/transformation, but is is needed in the bundle obviously.

That file is imported by Rooms.vue.

This is my project structure:

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

In my vue.config.js, I already tried this:

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

How can I exclude that specific file?


Solution

  • I figured it out:

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