简体   繁体   English

从汇总中排除文件

[英]Exclude a file from rollup

I'm developing an application in Polymer and lit-element and uses rollup to bundle all the files.我正在 Polymer 和 lit-element 中开发一个应用程序,并使用汇总来捆绑所有文件。 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.问题是我在根目录中有一个名为“config.js”的文件,他的 function 用于根据用户需要配置应用程序。 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当我rollup -c config.js文件被添加到包中时,这不是我想要的

I'm using the dev dependency "rollup-plugin-copy": "^3.3.0" .我正在使用开发依赖"rollup-plugin-copy": "^3.3.0" In my rollup.config.js file (starting from what @open-wc create for me), I add在我的rollup.config.js文件中(从@open-wc为我创建的内容开始),我添加

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.这会复制我的imageconfig目录和内容、 manifest.json文件等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM