简体   繁体   English

使用webpack和ManifestRevisionPlugin排除文件(即.DS_Store)

[英]Exclude files (i.e. .DS_Store) with webpack and ManifestRevisionPlugin

When I run build or watch in my webpack app, it throws an exception when it tries to parse the macOS .DS_Store metadata files. 当我在Webpack应用程序中运行build或watch时,尝试解析macOS .DS_Store元数据文件时会引发异常。 How do I configure it to ignore those files? 如何配置它以忽略那些文件?

ERROR in ./assets/preview/.DS_Store
Module parse failed: /Users/greg/projects/maven_book/assets/preview/.DS_Store Unexpected character '' (1:0)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected character '' (1:0)
    at Parser.pp$4.raise (/Users/greg/projects/maven_book/node_modules/acorn/dist/acorn.js:2221:15)
    at Parser.pp$7.getTokenFromCode (/Users/greg/projects/maven_book/node_modules/acorn/dist/acorn.js:2756:10)
    at Parser.pp$7.readToken (/Users/greg/projects/maven_book/node_modules/acorn/dist/acorn.js:2477:17)
    at Parser.pp$7.nextToken (/Users/greg/projects/maven_book/node_modules/acorn/dist/acorn.js:2468:15)
    at Parser.parse (/Users/greg/projects/maven_book/node_modules/acorn/dist/acorn.js:515:10)
    at Object.parse (/Users/greg/projects/maven_book/node_modules/acorn/dist/acorn.js:3098:39)
    at Parser.parse (/Users/greg/projects/maven_book/node_modules/webpack/lib/Parser.js:902:15)
    at NormalModule.<anonymous> (/Users/greg/projects/maven_book/node_modules/webpack/lib/NormalModule.js:104:16)
    at NormalModule.onModuleBuild (/Users/greg/projects/maven_book/node_modules/webpack-core/lib/NormalModuleMixin.js:310:10)
    at nextLoader (/Users/greg/projects/maven_book/node_modules/webpack-core/lib/NormalModuleMixin.js:275:25)
    at /Users/greg/projects/maven_book/node_modules/webpack-core/lib/NormalModuleMixin.js:259:5
    at Storage.finished (/Users/greg/projects/maven_book/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:38:16)
    at /Users/greg/projects/maven_book/node_modules/graceful-fs/graceful-fs.js:78:16
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:416:3)

and here's my full webpack config: 这是我完整的webpack配置:

var path = require('path');

var ExtractTextPlugin = require('extract-text-webpack-plugin');
var ManifestRevisionPlugin = require('manifest-revision-webpack-plugin');

var rootAssetPath = './assets';

module.exports = {
  context: __dirname,
  entry: {
    main_js: [
      rootAssetPath + '/j/main.js'
    ],
    main_css: [
      rootAssetPath + '/c/main.scss'
    ]
  },
  output: {
    path: './build/assets',
    publicPath: 'http://localhost:2992/assets/',
    filename: '[name].[chunkhash].js',
    chunkFilename: '[id].[chunkhash].js'
  },
  resolve: {
    modulesDirectories: ['node_modules'],
    extensions: ['', '.js', '.scss']
  },
  module: {
    loaders: [
      {
        test: /\.js$/i,
        loader: 'babel-loader',
        exclude: /node_modules/
      },
      {
        test: /\.css$/i,
        loader: ExtractTextPlugin.extract('style')
      },
      {
        test: /\.scss$/i,
        loader: ExtractTextPlugin.extract(
                    'style',
                    'css?sourceMap!sass?sourceMap'
                )
      },
      {
        test: /\.(jpe?g|png|gif|svg([\?]?.*))$/i,
        loaders: [
          'file?context=' + rootAssetPath + '&name=[path][name].[hash].[ext]',
          'image?bypassOnDebug&optimizationLevel=7&interlaced=false'
        ]
      },
      {
        test: /\.(eot|svg|ttf|woff|woff2)$/,
        // loader: 'file?name=public/fonts/[name].[ext]'
        loader: 'file?context=' + rootAssetPath + '&name=[path][name].[hash].[ext]'
      }
    ]
  },
  plugins: [
    new ExtractTextPlugin('[name].[chunkhash].css'),
    new ManifestRevisionPlugin(path.join('build', 'manifest.json'), {
      rootAssetPath: rootAssetPath,
      ignorePaths: ['/c', '/j']
    })
  ]
};

I'm not quite sure what DS_STORE files are. 我不太清楚什么是DS_STORE文件。 But when you configure your loaders, provide an exclude for these files. 但是,在配置加载程序时,请为这些文件提供排除项

Could you provide your webpack config, specifically the loader config, and demo.css? 您能否提供您的webpack配置,特别是加载器配置和demo.css? I can provide you the configuration. 我可以为您提供配置。

The issue here was that ManifestRevisionPlugin was reading the directory, and picking up .DS_Store files. 这里的问题是ManifestRevisionPlugin正在读取目录,并拾取.DS_Store文件。 To fix it, I added an exclude regex: 为了解决这个问题,我添加了一个排除正则表达式:

new ManifestRevisionPlugin(path.join('build', 'manifest.json'), {
  rootAssetPath: rootAssetPath,
  ignorePaths: ['/c', '/j', /.*\.DS_Store/]
})

暂无
暂无

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

相关问题 有人可以通过 GitHub 存储库从我的本地系统收集文件吗? 我看到 DS_Store 文件可能会打开这种可能性 - Could someone have gathered files from my local system via a GitHub repo? I see that DS_Store files might open up this possibility Photoshop脚本忽略.ds_store - Photoshop script to ignore .ds_store 在 Vue 单元测试中模拟 webpack “externals”(即 jquery)的正确方法(使用 mocha) - Correct way to mock webpack “externals” (i.e. jquery) in Vue unit tests (using mocha) 如何从 splitchunk webpack 中排除多个文件? - How can I exclude multiple files from splitchunk webpack? 我可以将值的“目标”(即SpanID.textContent)存储在数组中吗? (HTML / JS) - Can I store the “destination” (i.e. SpanID.textContent) of a value in an array? (HTML/JS) 排除webpack中的一些css文件 - Exclude some css files in webpack 如何使用angularjs在数据库中存储多个复选框的值(即“ Y”-表示已选中,“ N”-表示未选中)? - How to store values(i.e. 'Y'- for checked, 'N' - for unchecked) of multiple checkbox in database using angularjs? 我应该如何在流星项目中加载外部文件(即js,css,html)? - How should i load external files(i.e. js,css,html) in meteor project? 如何制作RequireJS应用模块,即随时随地下载文件 - How to make a RequireJS App Modular i.e. download files on the go, not at once Javascript - IE、Chrome、Firefox - 包含 external.js 文件的工作原理? - Javascript - I.E., Chrome, Firefox - How inclusion of external .js files works?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM