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

Enable production source maps for index.js, fix CSS sourcemaps #27291

Merged
merged 9 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion docs/content/installation/from-source.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ If pre-built frontend files are present it is possible to only build the backend
TAGS="bindata" make backend
```

Webpack source maps are by default enabled in development builds and disabled in production builds. They can be enabled by setting the `ENABLE_SOURCEMAP=true` environment variable.
Webpack source maps are limited by default to conserve space. When `ENABLE_SOURCEMAP=true` is set, the webpack build will generate all source maps.

## Test

Expand Down
2 changes: 1 addition & 1 deletion docs/content/installation/from-source.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ TAGS="bindata sqlite sqlite_unlock_notify" make build
TAGS="bindata" make backend
```

在开发构建中,默认启用 Webpack 源映射,在生产构建中禁用。可以通过设置`ENABLE_SOURCEMAP=true`环境变量来启用它们
默认情况下,Webpack 源映射受到限制以节省空间。 当设置`ENABLE_SOURCEMAP=true`时,webpack 构建将生成所有源映射

## 测试

Expand Down
19 changes: 12 additions & 7 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ for (const path of glob('web_src/css/themes/*.css')) {

const isProduction = env.NODE_ENV !== 'development';

let sourceMapEnabled;
// The production build only generates limited sourcemaps to conserve binary size.
// When in development or when ENABLE_SOURCEMAP=true, generate all source maps.
let fullSourceMapEnabled;
if ('ENABLE_SOURCEMAP' in env) {
sourceMapEnabled = env.ENABLE_SOURCEMAP === 'true';
fullSourceMapEnabled = env.ENABLE_SOURCEMAP === 'true';
} else {
sourceMapEnabled = !isProduction;
fullSourceMapEnabled = !isProduction;
}

const filterCssImport = (url, ...args) => {
Expand Down Expand Up @@ -105,7 +107,9 @@ export default {
css: !LightningCssMinifyPlugin,
legalComments: 'none',
}),
LightningCssMinifyPlugin && new LightningCssMinifyPlugin(),
LightningCssMinifyPlugin && new LightningCssMinifyPlugin({
sourceMap: fullSourceMapEnabled,
}),
],
splitChunks: {
chunks: 'async',
Expand Down Expand Up @@ -143,7 +147,7 @@ export default {
{
loader: 'css-loader',
options: {
sourceMap: sourceMapEnabled,
sourceMap: fullSourceMapEnabled,
url: {filter: filterCssImport},
import: {filter: filterCssImport},
},
Expand Down Expand Up @@ -181,9 +185,10 @@ export default {
filename: 'css/[name].css',
chunkFilename: 'css/[name].[contenthash:8].css',
}),
sourceMapEnabled && (new SourceMapDevToolPlugin({
new SourceMapDevToolPlugin({
filename: '[file].[contenthash:8].map',
})),
...(!fullSourceMapEnabled && {include: /^js\/index\.js$/}),
}),
new MonacoWebpackPlugin({
filename: 'js/monaco-[name].[contenthash:8].worker.js',
}),
Expand Down