Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: improve dev sourcemap #6818

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/serious-birds-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@ice/webpack-config': patch
'@ice/rspack-config': patch
'@ice/shared-config': patch
---

fix: imporve dev sourcemap
6 changes: 3 additions & 3 deletions packages/rspack-config/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path';
import { createRequire } from 'module';
import { getDefineVars, getCompilerPlugins, getJsxTransformOptions, getAliasWithRoot, skipCompilePackages } from '@ice/shared-config';
import { getDefineVars, getCompilerPlugins, getJsxTransformOptions, getAliasWithRoot, skipCompilePackages, getDevtoolValue } from '@ice/shared-config';
import type { Config, ModifyWebpackConfig } from '@ice/shared-config/types';
import type { Configuration, rspack as Rspack } from '@rspack/core';
import lodash from '@ice/bundles/compiled/lodash/index.js';
Expand Down Expand Up @@ -71,6 +71,7 @@ const getConfig: GetConfig = async (options) => {
configureWebpack = [],
minimizerOptions = {},
optimizePackageImports = [],
sourceMap,
} = taskConfig || {};
const isDev = mode === 'development';
const absoluteOutputDir = path.isAbsolute(outputDir) ? outputDir : path.join(rootDir, outputDir);
Expand Down Expand Up @@ -151,8 +152,6 @@ const getConfig: GetConfig = async (options) => {
rules: [
{
test: /\.(jsx?|tsx?|mjs)$/,
// Set enforce: 'post' to make sure the compilation-loader is executed after other transformers.
enforce: 'post',
...(excludeRule ? { exclude: new RegExp(excludeRule) } : {}),
use: {
loader: 'builtin:compilation-loader',
Expand Down Expand Up @@ -232,6 +231,7 @@ const getConfig: GetConfig = async (options) => {
infrastructureLogging: {
level: 'warn',
},
devtool: getDevtoolValue(sourceMap),
devServer: {
allowedHosts: 'all',
headers: {
Expand Down
2 changes: 2 additions & 0 deletions packages/shared-config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import getDefineVars from './getDefineVars.js';
import getPostcssOpts from './getPostcssOpts.js';
import getCSSModuleLocalIdent from './getCSSModuleLocalIdent.js';
import getAliasWithRoot from './getAlias.js';
import getDevtoolValue from './utils/getDevtool.js';

export {
getCSSModuleLocalIdent,
Expand All @@ -17,4 +18,5 @@ export {
getDefineVars,
getPostcssOpts,
getAliasWithRoot,
getDevtoolValue,
};
16 changes: 16 additions & 0 deletions packages/shared-config/src/utils/getDevtool.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { Config } from '../types';

interface GetDevtoolOptions<T = any> {
(sourceMap: Config['sourceMap']): T;
}

const getDevtoolValue: GetDevtoolOptions = (sourceMap) => {
if (typeof sourceMap === 'string') {
return sourceMap;
} else if (sourceMap === false) {
return false;
}
return 'source-map';
};

export default getDevtoolValue;
11 changes: 1 addition & 10 deletions packages/webpack-config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import ESlintPlugin from '@ice/bundles/compiled/eslint-webpack-plugin/index.js';
import CopyPlugin from '@ice/bundles/compiled/copy-webpack-plugin/index.js';
import type { NormalModule, Compiler, Configuration } from 'webpack';
import type webpack from 'webpack';
import { compilationPlugin, compileExcludes, getCompilerPlugins, getDefineVars, getAliasWithRoot } from '@ice/shared-config';
import { compilationPlugin, compileExcludes, getCompilerPlugins, getDefineVars, getAliasWithRoot, getDevtoolValue } from '@ice/shared-config';
import type { Config, ModifyWebpackConfig } from '@ice/shared-config/types.js';
import configAssets from './config/assets.js';
import configCss from './config/css.js';
Expand Down Expand Up @@ -427,12 +427,3 @@ export function getWebpackConfig(options: GetWebpackConfigOptions): Configuratio
.reduce((result, next: ModifyWebpackConfig<Configuration, typeof webpack>) => next(result, ctx), webpackConfig);
}

function getDevtoolValue(sourceMap: Config['sourceMap']) {
if (typeof sourceMap === 'string') {
return sourceMap;
} else if (sourceMap === false) {
return false;
}

return 'source-map';
}
Loading