refactor: warnfix plugin

This commit is contained in:
Pooya Parsa 2017-12-08 12:12:18 +03:30
parent 81bb278305
commit 9f72e4a6e2
3 changed files with 20 additions and 16 deletions

View File

@ -74,7 +74,7 @@ export default class Builder {
return { return {
src: this.nuxt.resolvePath(p.src), src: this.nuxt.resolvePath(p.src),
ssr: (p.ssr !== false), ssr: (p.ssr !== false),
name: basename(p.src, extname(p.src)).replace(/[^a-zA-Z?\d\s:]/g, '') + '_' + hash(p.src) name: basename(p.src, 'nuxt_plugin_' + extname(p.src)).replace(/[^a-zA-Z?\d\s:]/g, '') + '_' + hash(p.src)
} }
}), p => p.name) }), p => p.name)
} }

View File

@ -4,6 +4,7 @@ import { join, resolve } from 'path'
import webpack from 'webpack' import webpack from 'webpack'
import { isUrl, urlJoin } from 'utils' import { isUrl, urlJoin } from 'utils'
import TimeFixPlugin from './timefix-plugin' import TimeFixPlugin from './timefix-plugin'
import WarnFixPlugin from './warnfix-plugin'
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
@ -110,6 +111,9 @@ export default function webpackBaseConfig(name) {
config.plugins.unshift(new TimeFixPlugin()) config.plugins.unshift(new TimeFixPlugin())
} }
// Hide warnings about plugins without a default export (#1179)
config.plugins.push(new WarnFixPlugin())
// CSS extraction // CSS extraction
const extractCSS = this.options.build.extractCSS const extractCSS = this.options.build.extractCSS
if (extractCSS) { if (extractCSS) {
@ -120,21 +124,6 @@ export default function webpackBaseConfig(name) {
config.plugins.push(new ExtractTextPlugin(extractOptions)) config.plugins.push(new ExtractTextPlugin(extractOptions))
} }
// Workaround for hiding Warnings about plugins without a default export (#1179)
/* istanbul ignore next */
config.plugins.push({
apply(compiler) {
compiler.plugin('done', stats => {
stats.compilation.warnings = stats.compilation.warnings.filter(warn => {
if (warn.name === 'ModuleDependencyWarning' && warn.message.includes(`export 'default'`) && warn.message.includes('plugin')) {
return false
}
return true
})
})
}
})
// -------------------------------------- // --------------------------------------
// Dev specific config // Dev specific config
// -------------------------------------- // --------------------------------------

View File

@ -0,0 +1,15 @@
export default class WarnFixPlugin {
apply(compiler) {
compiler.plugin('done', stats => {
stats.compilation.warnings = stats.compilation.warnings.filter(warn => {
/* istanbul ignore next */
if (warn.name === 'ModuleDependencyWarning' &&
warn.message.includes(`export 'default'`) &&
warn.message.indexOf('nuxt_plugin_') === 0) {
return false
}
return true
})
})
}
}