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

[Bug]: The development mode is normal, and the packaging is reported to report an error #7012

Closed
djkloop opened this issue Jul 2, 2024 · 4 comments · Fixed by #7014
Closed
Labels
bug Something isn't working pending triage The issue/PR is currently untouched.

Comments

@djkloop
Copy link

djkloop commented Jul 2, 2024

Version

System:
    OS: Windows 10 10.0.19045
    CPU: (12) x64 12th Gen Intel(R) Core(TM) i5-12400
    Memory: 14.81 GB / 31.78 GB
  Browsers:
    Edge: Chromium (126.0.2592.81)
    Internet Explorer: 11.0.19041.4355
  npmPackages:
    @rsbuild/core: ^0.7.9 => 0.7.9
    @rsbuild/plugin-babel: ^0.7.9 => 0.7.9
    @rsbuild/plugin-node-polyfill: ^0.7.10 => 0.7.10
    @rsbuild/plugin-sass: ^0.7.9 => 0.7.9
    @rsbuild/plugin-vue2: ^0.7.9 => 0.7.9
    @rsbuild/plugin-vue2-jsx: ^0.7.9 => 0.7.9

Details

The development model is normal, but I reported an error when I pack it ... but it seems that the packaging has been completed

QQ_1719896186822

Reproduce link

none

Reproduce Steps

import { defineConfig, loadEnv } from '@rsbuild/core';

// vue 插件
import { pluginVue2 } from '@rsbuild/plugin-vue2';
import { pluginBabel } from '@rsbuild/plugin-babel';
import { pluginVue2Jsx } from '@rsbuild/plugin-vue2-jsx';
import { pluginNodePolyfill } from '@rsbuild/plugin-node-polyfill';
import { pluginSass } from '@rsbuild/plugin-sass';

import dayjs from 'dayjs';

import path from 'node:path';

//
process.env.VUE_APP_VERSION = require('./package.json').version;
process.env.VUE_APP_BUILD_TIME = dayjs().format('YYYY-M-D HH:mm:ss');

// 适配 vue-cli 中的变量
const { publicVars } = loadEnv({ prefixes: ['VUE_APP_'] });
// 适配别名配置
const aliasOptions = {
	'@': path.resolve(__dirname, './src'),
	'worker-loader': require.resolve('worker-rspack-loader'),
};

const sourceOptions = {
	define: publicVars,
	alias: aliasOptions,
};

// html 插件适配
const htmlOptions = {
	template: './public/index.html',
	//
	templateParameters: {
		// 生产环境里面的cdn
		cdn: {
			css: [],
			js: [],
		},
	},
};

console.log(`web_当前版本: -> ${process.env.VUE_APP_VERSION} <-`)
console.log(`是否是mock: -> ${process.env.VUE_APP_BUILD_MODE === 'true' ? '是' : '否'} <-`)
console.log(`web_请求后台_url_地址: -> ${process.env.VUE_APP_PUBLIC_PATH} <-\n`)

export default defineConfig({
	// source适配
	source: sourceOptions,
	//
	resolve: {
		alias: aliasOptions,
	},
	// html适配
	html: htmlOptions,
	// 各种 webpack 插件
	plugins: [
		pluginBabel({
			include: /\.(?:jsx|tsx)$/,
			exclude: /[\\/]node_modules[\\/]/,
		}),
		pluginVue2Jsx({
			vueJsxOptions: {
				compositionAPI: true
			}
		}),
		pluginVue2(),
		pluginSass({
			sassLoaderOptions: {
				api: 'legacy',
				additionalData: `@import '~@/assets/style/public.scss';`,
			},
		}),
		pluginNodePolyfill()
	],
	// 
	server: {
		proxy: {
			// ...
		}
	}
});
@djkloop
Copy link
Author

djkloop commented Jul 2, 2024

感觉像是打完了...但不知道最后报错了...

QQ_1719896793396

@djkloop
Copy link
Author

djkloop commented Jul 2, 2024

找到源码处了,这样的代码是不是错的....还是编译的问题...这段代码在vue-cli3确实可以打包

QQ_1719897017991

@xc2
Copy link
Collaborator

xc2 commented Jul 2, 2024

Thanks for report.

Minimal reproduction

// index.js
if (false) {
  const hasConsole = typeof console === 'undefined';
}
// rspack.config.js
module.exports = {
  mode: "none",
  devtool: false,
  entry: './src/index.js'.
  optimization: {
    innerGraph: true,
  }
};

Expected

/******/ (() => { // webpackBootstrap
var __webpack_exports__ = {};
if (false) {}




/******/ })()
;

Actually Got

(() => { // webpackBootstrap
var __webpack_exports__ = {};
if (false) {}(/* unused pure expression or super */ null && ())




})()
;

@chenjiahan chenjiahan transferred this issue from web-infra-dev/rsbuild Jul 2, 2024
@chenjiahan
Copy link
Member

Transfered to Rspack repo

@xc2 xc2 added bug Something isn't working pending triage The issue/PR is currently untouched. labels Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pending triage The issue/PR is currently untouched.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants