Skip to content

Commit 0546611

Browse files
author
baitu.huang
committed
fixing
1 parent 35bf29e commit 0546611

File tree

4 files changed

+27
-21
lines changed

4 files changed

+27
-21
lines changed

Diff for: lib/ignore-module-loader.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ module.exports.pitch = function ignoreLoaderPitch () {
2424
const matched = pluginOptions.ignoreFiles.find(v => v.test(this.resourcePath))
2525
if (matched) {
2626
const rawRequest = getRequestRes(this._module.rawRequest || this.request)
27-
const vueComponent = pluginOptions.watch && this.hot && /\.vue(\.html)?$/.test(this.resourcePath)
27+
// const vueComponent = pluginOptions.watch && this.hot && /\.vue(\.html)?$/.test(this.resourcePath)
2828
const logMsg = JSON.stringify(
2929
`${PLUGIN_NAME} warning: ` +
3030
`This module ${rawRequest} was ignored due to flag ${JSON.stringify(matched.__flag_name__)}`
3131
)
3232
return `process.env.NODE_ENV === 'development' && console.warn(${logMsg})\n` +
33-
(vueComponent ? `module.hot && module.hot.dispose(function(data) {data.__vue_component_hot__ = true})\n` : '') +
33+
// (vueComponent ? `module.hot && module.hot.dispose(function(data) {data.__vue_component_hot__ = true})\n` : '') +
3434
'module.exports = undefined'
3535
}
3636
}

Diff for: lib/plugin.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const assert = require('assert')
2+
const webpack = require('webpack')
23

34
const {
45
PLUGIN_NAME,
@@ -91,10 +92,15 @@ module.exports = class VueFlagsWebpackPlugin {
9192
}
9293
})
9394
// prepend to vue-loader, exec after vue-loader
94-
vueUses.splice(index, 0, {
95-
loader: require.resolve('./template-loader'),
96-
options: { watch: this.pluginOptions.watch }
97-
})
95+
if (this.pluginOptions.watch) {
96+
vueUses.splice(index, 0, {
97+
loader: require.resolve('./template-loader')
98+
})
99+
}
100+
// vueUses.splice(index, 0, {
101+
// loader: require.resolve('./template-loader'),
102+
// options: { watch: this.pluginOptions.watch }
103+
// })
98104
}
99105
// prepend ignore module pitch loader
100106
if (this.pluginOptions.ignoreFiles) {
@@ -130,7 +136,6 @@ module.exports = class VueFlagsWebpackPlugin {
130136
})
131137

132138
// apply flag variable plugin
133-
const webpack = require('webpack')
134139
const constPlugin = this.pluginOptions.watch ? new webpack.ProvidePlugin({
135140
[this.pluginOptions.namespace]: RESOLVED_FLAGS_PATH
136141
}) : new webpack.DefinePlugin({

Diff for: lib/resolve-options.js

+1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ function setOptions ({ flags, ignoreFiles, namespace, watch }, context, watchOpt
128128
if (typeof flags === 'string') {
129129
if (!path.isAbsolute(flags)) {
130130
flags = path.resolve(context, flags)
131+
flags = require.resolve(flags)
131132
}
132133
const stats = fs.statSync(flags)
133134
if (!stats.isFile()) {

Diff for: lib/template-loader.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
const loaderUtils = require('loader-utils')
22
const { RESOLVED_FLAGS_PATH, IF_FLAG } = require('./constants')
33
const ifDirReg = new RegExp(`\\s${IF_FLAG}(?:\\s*(=)\\s*(?:"([^"]+)"+|'([^']+)'+|([^\\s"'=<>\`]+)))`)
4-
const hotReloadRegs = [/module\.hot\.accept\(/, /module\.hot\.data/, /vue/]
4+
// const hotReloadRegs = [/module\.hot\.accept\(/, /module\.hot\.data/, /vue/]
55

66
module.exports = function vueFlagsTemplateLoader (source, map) {
7-
let vue, type
8-
const { watch } = loaderUtils.getOptions(this)
9-
if (!watch) {
10-
return this.callback(null, source, map)
11-
}
7+
// let vue, type
8+
// const { watch } = loaderUtils.getOptions(this)
9+
// if (!watch) {
10+
// return this.callback(null, source, map)
11+
// }
1212
if (this.resourceQuery) {
13-
({ vue, type } = loaderUtils.parseQuery(this.resourceQuery))
14-
}
15-
if (vue && type === 'template' && ifDirReg.test(source)) {
16-
this.addDependency(RESOLVED_FLAGS_PATH)
17-
}
18-
if (!type && this.hot && hotReloadRegs.every(r => r.test(source))) {
19-
// create component hot reload record by removing `module.hot.data`, see `vue-hot-reload-api`
20-
source = 'module.hot && module.hot.data && module.hot.data.__vue_component_hot__ && (module.hot.data = undefined);\n' + source
13+
const { vue, type } = loaderUtils.parseQuery(this.resourceQuery)
14+
if (vue && type === 'template' && ifDirReg.test(source)) {
15+
this.addDependency(RESOLVED_FLAGS_PATH)
16+
}
2117
}
18+
// if (!type && this.hot && hotReloadRegs.every(r => r.test(source))) {
19+
// // create component hot reload record by removing `module.hot.data`, see `vue-hot-reload-api`
20+
// source = 'module.hot && module.hot.data && module.hot.data.__vue_component_hot__ && (module.hot.data = undefined);\n' + source
21+
// }
2222
this.callback(null, source, map)
2323
}

0 commit comments

Comments
 (0)