使用vue的开发服务器忽略新文件

时间:2019-10-01 10:59:01

标签: vue.js webpack

每次使用我的应用程序(pre-build-webpacknpm run serve时,我都使用npm run build插件将多个json文件合并到1个json数组中,但是问题是它得到了启动开发服务器时陷入了无限的webpack编译循环。我设法通过使用watch-ignore-webpack-plugin插件找到了解决问题的方法,该插件最初似乎已解决了该问题-Webpack现在将编译所有内容两次(看起来),然后一切正常,我可以访问本地服务器。但是现在的问题是,当我访问localhost:8080时,什么都没有。屏幕为空白,console.log()没有任何内容,因此我不知道该怎么办。

如果有人看到过类似的东西或知道如何解决它,请告诉我。如果您需要任何其他信息,请让我知道。

版本:

  • vue:2.6.10(如package.json所示)
  • vue-cli:3.11.0(在cmd中运行vue -V
  • pre-build-webpack:0.1.0
  • watch-ignore-webpack-plugin:1.0.0
  • webpack-log:3.0.1

vue.config.js(已删除所有不相关的内容):

const WebpackPreBuildPlugin = require('pre-build-webpack');
const WatchIgnorePlugin = require('watch-ignore-webpack-plugin');

module.exports = {
  configureWebpack: {
    plugins: [
      new WebpackPreBuildPlugin(() => {

        const fs = require('fs');
        const glob = require('glob');
        const log = require('webpack-log')({ name: 'ATTENTION!' });
        const output = [];
        const exclude = [];

        glob('./src/components/mods/**/*.json', (err, paths) => {
          paths.forEach(path => {
            const content = JSON.parse(fs.readFileSync(path, 'utf-8'));
            const pathSplit = path.split('/');
            const modFolderName = pathSplit[pathSplit.length - 2]

            if(!output.filter(val => val.id === content.id)[0]) {
              if(exclude.indexOf(modFolderName) === -1) {
                output.push(content);
              } else {
                log.warn(`SKIPPING CONTENTS OF "${modFolderName}"`);
              }
            } else {
              log.error(`MOD WITH ID "${content.id}" ALREADY EXISTS!`);
              process.exit(0);
            }
          });

          // If I take out this line, the infinite loop doesn't occur, but then, of 
          // course, I don't get my merged json file either.
          fs.writeFileSync('./src/config/modules/layoutConfig.json', JSON.stringify(output));
        });

      }),
      // Neither of the blow paths work.
      new WatchIgnorePlugin([/\layoutConfig.json$/]),
      // new WatchIgnorePlugin(['./src/config/modules/layoutConfig.json']),
    ]
  }
};

0 个答案:

没有答案