Exclude a file from rollup

3.4k Views Asked by At

I'm developing an application in Polymer and lit-element and uses rollup to bundle all the files. The thing is I have a file which name is "config.js" in root directory which his function is to configure the application based on user needs. The application will load that configuration file to show what's needed. I don't want to have that file included in the bundle, because I want it to be dynamically changed by the user.

The config I have in the app file is like this:

import sources from '../config.js';

the config file is located in root directory and is like this:

export { sources as default };

const sources = [
  ......
];

my rollup config:

import commonjs from 'rollup-plugin-commonjs';
import resolve from 'rollup-plugin-node-resolve';

const plugins = [
  resolve({
      mainFields: false,
      browser: true,
  }),
  commonjs()
];

export default [
  {
    input: 'src/index.js',
    output: {
      file: 'dist/app.js',
      format: 'umd'
    },
    plugins: [...plugins],
  },
];

When I rollup -c the config.js file is added to the bundle, that's not what I want

1

There are 1 best solutions below

0
On

I'm using the dev dependency "rollup-plugin-copy": "^3.3.0". In my rollup.config.js file (starting from what @open-wc create for me), I add

import copy from 'rollup-plugin-copy';
...
plugins: [
  html(),
  copy({
    // copy over images files and manifest
    targets: [
      { src: 'images', dest: 'dist' },
      { src: 'manifest.json', dest: 'dist' },
      { src: 'config', dest: 'dist' },
     ...
    ],
    ...

This copies over my image and config directory and contents, the manifest.json file, and others.