Skip to content

Ignoring files? #322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cgs opened this issue May 3, 2017 · 13 comments
Closed

Ignoring files? #322

cgs opened this issue May 3, 2017 · 13 comments

Comments

@cgs
Copy link

cgs commented May 3, 2017

Is there a good way to ignore/exclude files on the dev server? Webpack keeps choking on my emacs backup files, such as "foo.vue~". I'd like to ignore all files ending in "~" but I'm not sure how to do it.

I tried adding watchOptions.ignored to config/webpack/development.js to no avail:

module.exports = merge(sharedConfig, {
  devtool: 'sourcemap',

  stats: {
    errorDetails: true
  },

  output: {
    pathinfo: true
  },

  watchOptions: {
    ignored: "**/*~"
  }
})

Is something like the ignore-loader plugin necessary for this?

@ZackMattor
Copy link

ZackMattor commented May 4, 2017

I thought you could use the exclude option and pass it some regex?

(not tested at all....)

exclude: [
  /(~$)/,
]

https://webpack.js.org/configuration/module/#condition

@gauravtiwari
Copy link
Member

@cgs Could you please try what Zack suggested? We should probably add some excludes by default, but I guess that still won't be one size fits all (may be a config option would be better).

@cgs
Copy link
Author

cgs commented May 4, 2017

@gauravtiwari Trying the above:

11:08:14 webpack.1 | Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
11:08:14 webpack.1 |  - configuration has an unknown property 'exclude'. These properties are valid:
11:08:14 webpack.1 |    object { amd?, bail?, cache?, context?, dependencies?, devServer?, devtool?, entry, externals?, loader?, module?, name?, node?, output?, performance?, plugins?, profile?, recordsInputPath?, recordsOutputPath?, recordsPath?, resolve?, resolveLoader?, stats?, target?, watch?, watchOptions? }
11:08:14 webpack.1 |    For typos: please correct them.
11:08:14 webpack.1 |    For loader options: webpack 2 no longer allows custom properties in configuration.
11:08:14 webpack.1 |      Loaders should be updated to allow passing options via loader options in module.rules.
11:08:14 webpack.1 |      Until loaders are updated one can use the LoaderOptionsPlugin to pass these options to the loader:
11:08:14 webpack.1 |      plugins: [
11:08:14 webpack.1 |        new webpack.LoaderOptionsPlugin({
11:08:14 webpack.1 |          // test: /\.xxx$/, // may apply this only for some modules
11:08:14 webpack.1 |          options: {
11:08:14 webpack.1 |            exclude: ...
11:08:14 webpack.1 |          }
11:08:14 webpack.1 |        })
11:08:14 webpack.1 |      ]

So, I tried this in app/config/webpack/shared.js:

  plugins: [
    new webpack.EnvironmentPlugin(JSON.parse(JSON.stringify(env))),
    new ExtractTextPlugin(env.NODE_ENV === 'production' ? '[name]-[hash].css' : '[name].css'),
    new ManifestPlugin({ fileName: paths.manifest, publicPath, writeToFileEmit: true }),
    new webpack.LoaderOptionsPlugin({
      options: {
        exclude: /(~$)/
      }
    })

  ],

No dice there either. Sorry, new to webpack so I'm a bit lost!

@gauravtiwari
Copy link
Member

I think you would need to add that to loaders/vue.js

{
  test: /\.vue$/,
  // rest of the config
  exclude: [
    /(~$)/
  ]
}

@gauravtiwari
Copy link
Member

BTW, no need of LoaderOptionsPlugin

@ZackMattor
Copy link

Yeah, it should be per-loader that you can add exclusions. I agree there should be a concept of global settings that each loader could inherit off of?... (Just thinking out loud)

@cgs
Copy link
Author

cgs commented May 4, 2017

@gauravtiwari @ZackMattor My vue loader:

module.exports = {
  test: /\.vue~?$/,
  loader: 'vue-loader',
  options: {
    loaders: {
      scss: 'vue-style-loader!css-loader!sass-loader',
      sass: 'vue-style-loader!css-loader!sass-loader?indentedSyntax'
    }
  },
  exclude: [
    /vue~$/
  ]
}

It's still not excluding the file. It's still not clear to me if the pattern I want to exclude needs to be in "test" and "exclude" or just "exclude." I tried both.

On a separate note, even if this worked I'd need to do the same thing in the babel loader I'd guess for js files.

@gauravtiwari
Copy link
Member

module.exports = {
  test: /\.vue$/,
  loader: 'vue-loader',
  options: {
    loaders: {
      scss: 'vue-style-loader!css-loader!sass-loader',
      sass: 'vue-style-loader!css-loader!sass-loader?indentedSyntax'
    }
  },
  exclude: [
    /(~$)/
  ]
}

@cgs Please try the above loader 👍

@cgs
Copy link
Author

cgs commented May 4, 2017

Still not working.

@gauravtiwari
Copy link
Member

gauravtiwari commented May 4, 2017

Alright, just tested it out and think the problem is you need a new loader that test for that extension. Sorry for back and forth. So, what you need to do is -

yard add ignore-loader
// loaders/ignores.js
module.exports = {
  test: /.vue~$/,
  loader: 'ignore-loader'
}

@cgs
Copy link
Author

cgs commented May 4, 2017

@gauravtiwari Success! 👍 I had installed that at one point but was not using it correctly. Would adding something to the readme about this be helpful?

@gauravtiwari
Copy link
Member

Document this in README/guide - #372

@willhaslett-stripe
Copy link

willhaslett-stripe commented Oct 19, 2021

Just a thought. It seems like a .webpackerignore would be a simple and friendly solution here. All kinds of weird situations come up where one wants/needs to exclude a specific asset or set of assets from compilation, e.g., stylesheets that are only ever used for rendering a template to a string internally, not to the screen. One still wants such files in /assets so that asset links work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants