Skip to content

Commit

Permalink
fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
baitu.huang committed Jul 18, 2019
1 parent 35bf29e commit 0546611
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
4 changes: 2 additions & 2 deletions lib/ignore-module-loader.js
Expand Up @@ -24,13 +24,13 @@ 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 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` : '') +
// (vueComponent ? `module.hot && module.hot.dispose(function(data) {data.__vue_component_hot__ = true})\n` : '') +
'module.exports = undefined'
}
}
15 changes: 10 additions & 5 deletions lib/plugin.js
@@ -1,4 +1,5 @@
const assert = require('assert')
const webpack = require('webpack')

const {
PLUGIN_NAME,
Expand Down Expand Up @@ -91,10 +92,15 @@ module.exports = class VueFlagsWebpackPlugin {
}
})
// prepend to vue-loader, exec after vue-loader
vueUses.splice(index, 0, {
loader: require.resolve('./template-loader'),
options: { watch: this.pluginOptions.watch }
})
if (this.pluginOptions.watch) {
vueUses.splice(index, 0, {
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 Expand Up @@ -130,7 +136,6 @@ module.exports = class VueFlagsWebpackPlugin {
})

// apply flag variable plugin
const webpack = require('webpack')
const constPlugin = this.pluginOptions.watch ? new webpack.ProvidePlugin({
[this.pluginOptions.namespace]: RESOLVED_FLAGS_PATH
}) : new webpack.DefinePlugin({
Expand Down
1 change: 1 addition & 0 deletions lib/resolve-options.js
Expand Up @@ -128,6 +128,7 @@ 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()) {
Expand Down
28 changes: 14 additions & 14 deletions lib/template-loader.js
@@ -1,23 +1,23 @@
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/]
// 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)
}
// let vue, type
// const { watch } = loaderUtils.getOptions(this)
// if (!watch) {
// return this.callback(null, source, map)
// }
if (this.resourceQuery) {
({ 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
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)
}

0 comments on commit 0546611

Please sign in to comment.