手表模式下的汇总功能,具有两个版本的汇总功能

时间:2020-03-26 21:58:08

标签: rollup

最近我有一个奇怪的问题。当我运行rollup -cw时,Rollup将我的应用程序与Rollup v2.2.0捆绑在一起。一切都很好。

rollup v2.2.0
bundles ./src/index.html → build...
[Browsersync] Access URLs:
 ----------------------------------
       Local: http://localhost:8000
    External: http://10.0.0.13:8000
 ----------------------------------
          UI: http://localhost:3001
 UI External: http://localhost:3001
 ----------------------------------
[Browsersync] Serving files from: build
[Browsersync] Watching files...
(!) Circular dependencies
src/apollo/client.js -> src/apollo/resolvers/index.js -> src/apollo/resolvers/Query.js -> src/router/router.js -> src/apollo/auth.js -> src/apollo/client.js
node_modules/d3-selection/src/selection/index.js -> node_modules/d3-selection/src/selection/select.js -> node_modules/d3-selection/src/selection/index.js
node_modules/d3-selection/src/selection/index.js -> node_modules/d3-selection/src/selection/selectAll.js -> node_modules/d3-selection/src/selection/index.js
...and 17 more
(!) Generated an empty chunk
index
created build in 30.8s

[2020-03-26 23:42:30] waiting for changes...
[Browsersync] Reloading Browsers...
[Browsersync] Reloading Browsers... (buffered 302 events)

但是,如果我随后保存文件,则汇总会将应用程序与汇总v1.31.1捆绑在一起

rollup v1.31.1
bundles ./src/index.html → build, build/nomodule...
bundles ./src/index.html → build, build/nomodule...
bundles ./src/index.html → build, build/nomodule...
bundles ./src/index.html → build...
[!] (plugin copy) Error: EEXIST: file already exists, mkdir 'build/assets/systemjs/dist'
Error: EEXIST: file already exists, mkdir 'build/assets/systemjs/dist'

[!] (plugin copy) Error: EEXIST: file already exists, mkdir 'build/assets/systemjs/dist'
Error: EEXIST: file already exists, mkdir 'build/assets/systemjs/dist'

[!] (plugin copy) Error: EEXIST: file already exists, mkdir 'build/assets/systemjs/dist'
Error: EEXIST: file already exists, mkdir 'build/assets/systemjs/dist'

[!] (plugin Rollup Core) Error: Could not load /path/to/the-app/node_modules/@material/mwc-fab/node_modules/@material/mwc-ripple/ripple-directive.js (imported by /path/to/the-app/node_modules/@material/mwc-fab/mwc-fab-base.js): ENOENT: no such file or directory, open '/path/to/the-app/node_modules/@material/mwc-fab/node_modules/@material/mwc-ripple/ripple-directive.js'
Error: Could not load /path/to/the-app/node_modules/@material/mwc-fab/node_modules/@material/mwc-ripple/ripple-directive.js (imported by /path/to/the-app/node_modules/@material/mwc-fab/mwc-fab-base.js): ENOENT: no such file or directory, open '/path/to/the-app/node_modules/@material/mwc-fab/node_modules/@material/mwc-ripple/ripple-directive.js'

(!) Circular dependencies
src/apollo/client.js -> src/apollo/resolvers/index.js -> src/apollo/resolvers/Query.js -> src/router/router.js -> src/apollo/auth.js -> src/apollo/client.js
node_modules/d3-selection/src/selection/index.js -> node_modules/d3-selection/src/selection/select.js -> node_modules/d3-selection/src/selection/index.js
node_modules/d3-selection/src/selection/index.js -> node_modules/d3-selection/src/selection/selectAll.js -> node_modules/d3-selection/src/selection/index.js
...and 17 more
(!) Generated an empty chunk
index
created build in 31s

[2020-03-26 23:44:09] waiting for changes...
[Browsersync] Reloading Browsers...

请注意,第二个构建也将构建生产版本(nomodule)

此存储库中未安装汇总v1.31.1

AFAICT我没有需要汇总v1.31.1的软件包

> npm ls rollup
the-app@0.1.0 /path/to/the-app
├─┬ @open-wc/demoing-storybook@1.13.8
│ └── rollup@1.32.1
├── UNMET PEER DEPENDENCY rollup@2.2.0
└─┬ rollup-plugin-workbox@5.0.1
  └─┬ workbox-build@5.0.0
    └── rollup@1.32.1

npm ERR! peer dep missing: rollup@^1.20.0, required by @rollup/plugin-alias@3.0.1
npm ERR! peer dep missing: rollup@^1.20.0, required by @rollup/plugin-beep@0.1.2
npm ERR! peer dep missing: rollup@^1.20.0, required by @rollup/plugin-commonjs@11.0.2
npm ERR! peer dep missing: rollup@^1.20.0, required by @rollup/plugin-json@4.0.2
npm ERR! peer dep missing: rollup@^1.20.0, required by @rollup/plugin-node-resolve@7.1.1
npm ERR! peer dep missing: rollup@^1.20.0, required by @rollup/plugin-replace@2.3.1
npm ERR! peer dep missing: rollup@^0.65.2 || ^1.0.0, required by rollup-plugin-minify-html-literals@1.2.3
npm ERR! peer dep missing: rollup@^1.4.1, required by rollup-plugin-notify@1.1.0

我没有全局安装汇总,已经运行yarn global remove rollupnpm r -g rollup

这是我的rollup.config.js

import dotenv from 'dotenv';
import path from 'path';

import alias from '@rollup/plugin-alias';
import beep from '@rollup/plugin-beep';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import replace from '@rollup/plugin-replace';
import resolve from '@rollup/plugin-node-resolve';

import { generateSW } from 'rollup-plugin-workbox';
import { terser } from 'rollup-plugin-terser';
import babel from 'rollup-plugin-babel';
import browsersync from 'rollup-plugin-browsersync';
import copy from 'rollup-plugin-copy';
import graphql from '@kocal/rollup-plugin-graphql';
import html from '@open-wc/rollup-plugin-html';
import litcss from 'rollup-plugin-lit-css';
import minifyLitHtml from 'rollup-plugin-minify-html-literals';
import notify from 'rollup-plugin-notify';
import watchAssets from 'rollup-plugin-watch-assets';

dotenv.config();

const PROCESS_WATCHING =
  !!(process.argv.some(arg => !!arg.match(/-c?w/)) || process.argv.includes('--watch'));

const production = !PROCESS_WATCHING && process.env.NODE_ENV === 'production';

const replaceConfig = {
  ...redacted
};

const targets = [
  { src: 'node_modules/systemjs/dist', dest: 'build/assets/systemjs' },
  { src: 'node_modules/@webcomponents', dest: 'build/assets' },
  { src: 'src/favicon.ico', dest: 'build' },
  { src: 'src/favicon.ico', dest: 'build' },
  { src: 'src/manifest.webmanifest', dest: 'build' },
  { src: 'src/assets', dest: 'build' },
  { src: 'src/components/shared.css', dest: 'build' },
  { src: 'src/index.html', dest: 'build' },
  { src: 'src/*.css', dest: 'build' },
];

const customResolver = resolve({
  extensions: ['.js', '.json', '.html', '.graphql', '.css'],
  dedupe: id => id.includes('lit'),
});

const entries = [{
  find: /#(.*)\/(.*)\b/,
  replacement: path.resolve(__dirname, 'src/$1/$2'),
}, {
  find: /#(.*)\b/,
  replacement: path.resolve(__dirname, 'src/$1'),
}];

const esmOutput = {
  format: 'esm',
  dir: 'build',
  sourcemap: true,
};

const nomoduleOutput = {
  format: 'system',
  dir: 'build/nomodule',
  sourcemap: true,
};

const productionOutput = [esmOutput, nomoduleOutput].map(output => ({
  ...output,
  plugins: [
    terser(),
    minifyLitHtml(),
    generateSW(require('./workbox-config.js')),
  ],
}));

export default {
  input: './src/index.html',
  output: production ? productionOutput : esmOutput,
  watch: {
    include: 'src/**',
    clearScreen: false,
  },
  plugins: [
    html({ minify: production }),
    babel(),
    graphql(),
    json(),
    litcss({ uglify: production }),
    customResolver,
    alias({ entries, customResolver }),
    replace(replaceConfig),
    commonjs({ sourceMap: false }),
    copy({ targets, copyOnce: PROCESS_WATCHING }),
    ...PROCESS_WATCHING ? [
      watchAssets({ assets: ['src/**/*.html', 'src/**/*.css'] }),
      browsersync({
        port: 8000,
        server: 'build',
        single: true,
        watch: true,
        watchOptions: {
          awaitWriteFinish: {
            ignoreInitial: true,
            stabilityThreshold: 2000,
            pollInterval: 100,
            ignore: '/assets/**/*',
          },
        },
      }),
    ] : [],
    beep(),
    notify(),
  ],
  // Don't warn about `this` - typescript produces these.
  onwarn(warning, warn) {
    if (warning.code === 'THIS_IS_UNDEFINED') return;
    warn(warning);
  },

};

我尝试过的东西

  • 我尝试降级到汇总1.32
  • 我已经尝试过npm dedupe rollup
  • 我已经尝试过yarn global remove rollup
  • 我已经尝试过rm -rf node_modules ; rm package-lock.json ; npm i
  • 我尝试注释掉以下插件:
    • watchAssets
    • browsersync
    • 复制
    • 哔哔
    • 通知
    • html
  • 我尝试添加此插件:
{
  name: 'sanity-check',
  buildStart() {
    if (production) console.log('HEY!!!! IT\'S PRODUCTION');
  },
},

没有日志出现

没有骰子。

是什么原因导致这种双重生成行为,汇总1.31.1来自何处?

更新

1.31.1添加node_modules产生了此结果

$ rg "1\.31\.1" node_modules/@surma
node_modules/@surma/rollup-plugin-off-main-thread/package.json
55:    "rollup": "1.31.1"
$ npx npm-why @surma/rollup-plugin-off-main-thread
npx: installed 4 in 1.141s
  Who required @surma/rollup-plugin-off-main-thread:
  my-pwa > rollup-plugin-workbox > workbox-build > @surma/rollup-plugin-off-main-thread@1.2.0

因此,此错误可能是由于@surma/rollup-plugin-off-main-thread的固定汇总到特定版本引起的。

我不明白的是,这如何使npm引用两个汇总箱

0 个答案:

没有答案
相关问题