Skip to content

Commit c3b04ef

Browse files
committed
fix: dev环境给静态资源添加hash版本号,css已文件名添加hash后会导致css hot-reload失效
1 parent b3f6a1e commit c3b04ef

File tree

6 files changed

+21
-21
lines changed

6 files changed

+21
-21
lines changed

packages/react-webpack/src/react/base.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import webpack from 'webpack';
22
import * as path from 'path';
33
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
44
import TerserPlugin from 'terser-webpack-plugin';
5-
import common, { cwd, clientDir, getCoreConfig, getOptions } from '@srejs/common';
5+
import { cwd, clientDir, getCoreConfig, getOptions, isDev } from '@srejs/common';
66

77
import { loaderRules } from './loader';
88
import { getPlugin } from './plugin';
@@ -32,11 +32,11 @@ export function getBaseconfig(page, isServer = false, hotReload = false) {
3232
}
3333

3434
const config = {
35-
devtool: common.isDev() ? 'eval-source-map' : false,
36-
mode: common.isDev() ? 'development' : 'production',
35+
devtool: isDev() ? 'eval-source-map' : false,
36+
mode: isDev() ? 'development' : 'production',
3737
optimization: {
3838
usedExports: true,
39-
minimize: common.isDev() ? false : true,
39+
minimize: isDev() ? false : true,
4040
/**minimizer 提取css和js压缩 */
4141
minimizer: [
4242
new CssMinimizerPlugin(),
@@ -56,10 +56,10 @@ export function getBaseconfig(page, isServer = false, hotReload = false) {
5656
...tempObj
5757
}, //类别入口文件
5858
output: {
59-
publicPath: !common.isDev() ? prefixCDN : '/',
59+
publicPath: !isDev() ? prefixCDN : '/',
6060
libraryTarget: 'umd',
6161
globalObject: 'this', //webpack4之后如果umd构建在浏览器和node环境中均可使用需要设置成this
62-
filename: isServer ? '[name].js' : `[name]_[hash:8].js`, //打包后输出文件的文件名
62+
filename: isDev() || isServer ? '[name].js' : `[name]_[hash:8].js`, //打包后输出文件的文件名
6363
path: clientDir //打包后的文件存放的地方
6464
},
6565
stats: {

packages/react-webpack/src/react/plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function getPlugin(entryObj, isServer) {
6161
});
6262
webpackPlugin.push(
6363
new MiniCssExtractPlugin({
64-
filename: isServer ? '[name].css' : '[name]_[hash:8].css'
64+
filename: isDev() || isServer ? '[name].css' : '[name]_[hash:8].css'
6565
})
6666
);
6767
if (process.argv.indexOf('--analyzer') > -1 && !isServer) {

packages/vue-webpack/src/vue/base.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import webpack from 'webpack';
22
import * as path from 'path';
33
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
44
import TerserPlugin from 'terser-webpack-plugin';
5-
import common, { cwd, clientDir, getCoreConfig, getOptions } from '@srejs/common';
5+
import { cwd, clientDir, getCoreConfig, getOptions, isDev } from '@srejs/common';
66

77
import { loaderRules } from './loader';
88
import { getPlugin } from './plugin';
@@ -32,11 +32,11 @@ export function getBaseconfig(page, isServer = false, hotReload = false) {
3232
}
3333

3434
const config = {
35-
devtool: common.isDev() ? 'eval-source-map' : false,
36-
mode: common.isDev() ? 'development' : 'production',
35+
devtool: isDev() ? 'eval-source-map' : false,
36+
mode: isDev() ? 'development' : 'production',
3737
optimization: {
3838
usedExports: true,
39-
minimize: common.isDev() ? false : true,
39+
minimize: isDev() ? false : true,
4040
/**minimizer 提取css和js压缩 */
4141
minimizer: [
4242
new CssMinimizerPlugin(),
@@ -56,10 +56,10 @@ export function getBaseconfig(page, isServer = false, hotReload = false) {
5656
...tempObj
5757
}, //类别入口文件
5858
output: {
59-
publicPath: !common.isDev() ? prefixCDN : '/',
59+
publicPath: !isDev() ? prefixCDN : '/',
6060
libraryTarget: 'umd',
6161
globalObject: 'this',
62-
filename: isServer ? '[name].js' : `[name]_[hash:8].js`, //打包后输出文件的文件名
62+
filename: isDev() || isServer ? '[name].js' : `[name]_[hash:8].js`, //打包后输出文件的文件名
6363
path: clientDir //打包后的文件存放的地方
6464
},
6565
stats: {

packages/vue-webpack/src/vue/plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function getPlugin(entryObj, isServer) {
6464
!isDev() &&
6565
webpackPlugin.push(
6666
new MiniCssExtractPlugin({
67-
filename: isServer ? '[name].css' : '[name]_[hash:8].css'
67+
filename: isDev() || isServer ? '[name].css' : '[name]_[hash:8].css'
6868
})
6969
);
7070
if (process.argv.indexOf('--analyzer') > -1 && !isServer) {

packages/vue3-webpack/src/vue/base.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import webpack from 'webpack';
22
import * as path from 'path';
33
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
44
import TerserPlugin from 'terser-webpack-plugin';
5-
import common, { cwd, clientDir, getCoreConfig, getOptions } from '@srejs/common';
5+
import { cwd, clientDir, getCoreConfig, getOptions, isDev } from '@srejs/common';
66

77
import { loaderRules } from './loader';
88
import { getPlugin } from './plugin';
@@ -32,11 +32,11 @@ export function getBaseconfig(page, isServer = false, hotReload = false) {
3232
}
3333

3434
const config = {
35-
devtool: common.isDev() ? 'eval-source-map' : false,
36-
mode: common.isDev() ? 'development' : 'production',
35+
devtool: isDev() ? 'eval-source-map' : false,
36+
mode: isDev() ? 'development' : 'production',
3737
optimization: {
3838
usedExports: true,
39-
minimize: common.isDev() ? false : true,
39+
minimize: isDev() ? false : true,
4040
/**minimizer 提取css和js压缩 */
4141
minimizer: [
4242
new CssMinimizerPlugin(),
@@ -56,10 +56,10 @@ export function getBaseconfig(page, isServer = false, hotReload = false) {
5656
...tempObj
5757
}, //类别入口文件
5858
output: {
59-
publicPath: !common.isDev() ? prefixCDN : '/',
59+
publicPath: !isDev() ? prefixCDN : '/',
6060
libraryTarget: 'umd',
6161
globalObject: 'this',
62-
filename: isServer ? '[name].js' : `[name]_[hash:8].js`, //打包后输出文件的文件名
62+
filename: isDev() || isServer ? '[name].js' : `[name]_[hash:8].js`, //打包后输出文件的文件名
6363
path: clientDir //打包后的文件存放的地方
6464
},
6565
stats: {

packages/vue3-webpack/src/vue/plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function getPlugin(entryObj, isServer) {
6464
!isDev() &&
6565
webpackPlugin.push(
6666
new MiniCssExtractPlugin({
67-
filename: isServer ? '[name].css' : '[name]_[hash:8].css'
67+
filename: isDev() || isServer ? '[name].css' : '[name]_[hash:8].css'
6868
})
6969
);
7070
if (process.argv.indexOf('--analyzer') > -1 && !isServer) {

0 commit comments

Comments
 (0)