Skip to content

Commit

Permalink
remove hot-reload hack code because of vuejs/vue-loader#1569
Browse files Browse the repository at this point in the history
  • Loading branch information
baitu.huang committed Jul 19, 2019
1 parent 0546611 commit f9a58ae
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 21 deletions.
2 changes: 0 additions & 2 deletions lib/ignore-module-loader.js
Expand Up @@ -24,13 +24,11 @@ module.exports.pitch = function ignoreLoaderPitch () {
const matched = pluginOptions.ignoreFiles.find(v => v.test(this.resourcePath))
if (matched) {
const rawRequest = getRequestRes(this._module.rawRequest || this.request)
// const vueComponent = pluginOptions.watch && this.hot && /\.vue(\.html)?$/.test(this.resourcePath)
const logMsg = JSON.stringify(
`${PLUGIN_NAME} warning: ` +
`This module ${rawRequest} was ignored due to flag ${JSON.stringify(matched.__flag_name__)}`
)
return `process.env.NODE_ENV === 'development' && console.warn(${logMsg})\n` +
// (vueComponent ? `module.hot && module.hot.dispose(function(data) {data.__vue_component_hot__ = true})\n` : '') +
'module.exports = undefined'
}
}
4 changes: 0 additions & 4 deletions lib/plugin.js
Expand Up @@ -97,10 +97,6 @@ module.exports = class VueFlagsWebpackPlugin {
loader: require.resolve('./template-loader')
})
}
// vueUses.splice(index, 0, {
// loader: require.resolve('./template-loader'),
// options: { watch: this.pluginOptions.watch }
// })
}
// prepend ignore module pitch loader
if (this.pluginOptions.ignoreFiles) {
Expand Down
8 changes: 4 additions & 4 deletions lib/resolve-options.js
Expand Up @@ -128,11 +128,11 @@ function setOptions ({ flags, ignoreFiles, namespace, watch }, context, watchOpt
if (typeof flags === 'string') {
if (!path.isAbsolute(flags)) {
flags = path.resolve(context, flags)
flags = require.resolve(flags)
}
const stats = fs.statSync(flags)
if (!stats.isFile()) {
throw genError(`flags: ${flags} is not a file`)
try {
flags = require.resolve(flags)
} catch (err) {
throw genError(`Options: "flags" cannot be resolved, ${err.message}`)
}
}
if (watch) {
Expand Down
10 changes: 0 additions & 10 deletions lib/template-loader.js
@@ -1,23 +1,13 @@
const loaderUtils = require('loader-utils')
const { RESOLVED_FLAGS_PATH, IF_FLAG } = require('./constants')
const ifDirReg = new RegExp(`\\s${IF_FLAG}(?:\\s*(=)\\s*(?:"([^"]+)"+|'([^']+)'+|([^\\s"'=<>\`]+)))`)
// const hotReloadRegs = [/module\.hot\.accept\(/, /module\.hot\.data/, /vue/]

module.exports = function vueFlagsTemplateLoader (source, map) {
// let vue, type
// const { watch } = loaderUtils.getOptions(this)
// if (!watch) {
// return this.callback(null, source, map)
// }
if (this.resourceQuery) {
const { vue, type } = loaderUtils.parseQuery(this.resourceQuery)
if (vue && type === 'template' && ifDirReg.test(source)) {
this.addDependency(RESOLVED_FLAGS_PATH)
}
}
// if (!type && this.hot && hotReloadRegs.every(r => r.test(source))) {
// // create component hot reload record by removing `module.hot.data`, see `vue-hot-reload-api`
// source = 'module.hot && module.hot.data && module.hot.data.__vue_component_hot__ && (module.hot.data = undefined);\n' + source
// }
this.callback(null, source, map)
}
2 changes: 1 addition & 1 deletion test/options.test.js
Expand Up @@ -95,7 +95,7 @@ test(chalk.cyan('options test:invalid'), t => {
}, {
flags: 'aaaaaaaa',
namespace: 'F',
msg: /no such file or directory.+a{5,}/
msg: /Options: "flags" cannot be resolved, .+a{5,}/
}].forEach(option => {
const msg = option.msg
delete option.msg
Expand Down

0 comments on commit f9a58ae

Please sign in to comment.