Open CoderQuixote opened 5 hours ago
rspack配置如下 ` const path = require('path'); const rspack = require('@rspack/core'); const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin'); const {VueLoaderPlugin} = require('vue-loader'); const {RsdoctorRspackPlugin} = require('@rsdoctor/rspack-plugin');
function resolve(moduleName) { return require.resolve(moduleName); }
function assertResolve(dir) { return path.join(__dirname, dir); }
const config = {
context: dirname,
mode: 'production',
devtool: false,
target: ['web', 'es5'],
entry: {
'buildQuickly.all.umd.min': ['./src/entry.js'],
'buildQuickly.all.umd': ['./src/entry.js'],
'buildQuickly.renderEngine.umd.min': ['./src/engineEntry.js'],
'buildQuickly.renderEngine.umd': ['./src/engineEntry.js']
},
output: {
clean: true,
filename: '[name].js',
library: {
name: 'buildQuickly',
type: 'umd'
},
path: path.resolve(dirname, 'dist')
},
optimization: {
minimize: true,
minimizer: [
new rspack.SwcJsMinimizerRspackPlugin({
test: /min/,
minimizerOptions: {
format: {
comments: false,
},
},
}),
new rspack.LightningCssMinimizerRspackPlugin({
include: /min/,
minimizerOptions: {
errorRecovery: false,
},
}),
]
},
externals: [],
resolve: {
modules: ['node_modules', path.join(__dirname, '../node_modules')],
extensions: [
'.web.tsx',
'.web.ts',
'.web.jsx',
'.web.js',
'.ts',
'.tsx',
'.js',
'.jsx',
'.vue',
'.md',
'.json'
],
alias: {
'@': assertResolve('src'),
public: assertResolve('public')
},
fallback: ['child_process', 'cluster', 'dgram', 'dns', 'fs', 'module', 'net', 'readline', 'repl', 'tls'].reduce(
(acc, name) => Object.assign({}, acc, {[name]: 'empty'}),
{}
)
},
plugins: [
...(process.env.RSDOCTOR ? [
new RsdoctorRspackPlugin({
features: {
resolver: true
},
supports: {
generateTileGraph: true
},
port: 120
})
] : []),
new VueLoaderPlugin(),
// new rspack.CssExtractRspackPlugin(),
new CaseSensitivePathsPlugin()],
experiments: {
css: true
},
module: {
rules: [
{
test: /.vue$/,
exclude: /node_modules/,
use: [
{
loader: 'vue-loader',
options: {
// 注意,为了绝大多数功能的可用性,请确保该选项为 true
experimentalInlineMatchResource: true
}
}
]
},
{
test: /.(js|jsx)$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
// 插件先执行 再执行预设
plugins: ['@vue/babel-plugin-jsx'],
presets: ['@babel/preset-env']
}
}
]
},
// {
// test: /.css$/i,
// use: [
// rspack.CssExtractRspackPlugin.loader,
// 'css-loader',
// {
// loader: 'postcss-loader',
// options: {
// postcssOptions: {
// plugins: ['autoprefixer']
// },
// sourceMap: true
// }
// }
// ],
// type: 'javascript/auto'
// },
{
test: /\.less$/,
loader: 'less-loader',
type: 'css'
},
{
test: /\.svg$/,
use: ['vue-loader', resolve('./build/loaders/vue-svg-loader.js')]
}
]
}
};
function externalDep(config) { config.externals.push({ vue: { root: 'Vue', commonjs2: 'vue', commonjs: 'vue', amd: 'vue', module: 'vue' } });
config.externals.push({
dayjs: {
root: 'dayjs',
commonjs2: 'dayjs',
commonjs: 'dayjs',
amd: 'dayjs',
module: 'dayjs'
}
});
config.externals.push(function ({_context, request}, callback) {
if (/^dayjs\/plugin\//.test(request)) {
const name = request.replace(/\//g, '_');
return callback(null, {
root: name,
commonjs2: name,
commonjs: name,
amd: name,
module: name
});
}
callback();
});
config.externals.push({
'@xa-web/hua-design-vue3': {
root: 'huad', // root global variable
commonjs2: '@xa-web/hua-design-vue3', // module.exports = xxx
commonjs: '@xa-web/hua-design-vue3', // exports[“Library”] = xxx
amd: '@xa-web/hua-design-vue3', // define(["xxx"], factory)
module: '@xa-web/hua-design-vue3'
}
});
}
externalDep(config);
module.exports = config; `
css 打包出来存在一堆乱码的东西,导致模块丢失无法加载,排查了很久才发现是 css 打包出问题了,换回 1.0.0-alpha.5 就没问题,已经几个月了这个问题还没解决
scss 配置如下
rspack配置如下 ` const path = require('path'); const rspack = require('@rspack/core'); const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin'); const {VueLoaderPlugin} = require('vue-loader'); const {RsdoctorRspackPlugin} = require('@rsdoctor/rspack-plugin');
function resolve(moduleName) { return require.resolve(moduleName); }
function assertResolve(dir) { return path.join(__dirname, dir); }
const config = { context: dirname, mode: 'production', devtool: false, target: ['web', 'es5'], entry: { 'buildQuickly.all.umd.min': ['./src/entry.js'], 'buildQuickly.all.umd': ['./src/entry.js'], 'buildQuickly.renderEngine.umd.min': ['./src/engineEntry.js'], 'buildQuickly.renderEngine.umd': ['./src/engineEntry.js'] }, output: { clean: true, filename: '[name].js', library: { name: 'buildQuickly', type: 'umd' }, path: path.resolve(dirname, 'dist') }, optimization: { minimize: true, minimizer: [ new rspack.SwcJsMinimizerRspackPlugin({ test: /min/, minimizerOptions: { format: { comments: false, }, }, }), new rspack.LightningCssMinimizerRspackPlugin({ include: /min/, minimizerOptions: { errorRecovery: false, }, }), ] }, externals: [], resolve: { modules: ['node_modules', path.join(__dirname, '../node_modules')], extensions: [ '.web.tsx', '.web.ts', '.web.jsx', '.web.js', '.ts', '.tsx', '.js', '.jsx', '.vue', '.md', '.json' ], alias: { '@': assertResolve('src'), public: assertResolve('public') }, fallback: ['child_process', 'cluster', 'dgram', 'dns', 'fs', 'module', 'net', 'readline', 'repl', 'tls'].reduce( (acc, name) => Object.assign({}, acc, {[name]: 'empty'}), {} ) }, plugins: [ ...(process.env.RSDOCTOR ? [ new RsdoctorRspackPlugin({ features: { resolver: true }, supports: { generateTileGraph: true }, port: 120 }) ] : []), new VueLoaderPlugin(), // new rspack.CssExtractRspackPlugin(), new CaseSensitivePathsPlugin()], experiments: { css: true }, module: { rules: [ { test: /.vue$/, exclude: /node_modules/, use: [ { loader: 'vue-loader', options: { // 注意,为了绝大多数功能的可用性,请确保该选项为
true
experimentalInlineMatchResource: true } } ] }, { test: /.(js|jsx)$/, exclude: /node_modules/, use: [ { loader: 'babel-loader', options: { // 插件先执行 再执行预设 plugins: ['@vue/babel-plugin-jsx'], presets: ['@babel/preset-env'] } } ] }, // { // test: /.css$/i, // use: [ // rspack.CssExtractRspackPlugin.loader, // 'css-loader', // { // loader: 'postcss-loader', // options: { // postcssOptions: { // plugins: ['autoprefixer'] // }, // sourceMap: true // } // } // ], // type: 'javascript/auto' // },{ test: /\.less$/, loader: 'less-loader', type: 'css' }, { test: /\.svg$/, use: ['vue-loader', resolve('./build/loaders/vue-svg-loader.js')] } ] }
};
function externalDep(config) { config.externals.push({ vue: { root: 'Vue', commonjs2: 'vue', commonjs: 'vue', amd: 'vue', module: 'vue' } });
config.externals.push({ dayjs: { root: 'dayjs', commonjs2: 'dayjs', commonjs: 'dayjs', amd: 'dayjs', module: 'dayjs' } }); config.externals.push(function ({_context, request}, callback) { if (/^dayjs\/plugin\//.test(request)) { const name = request.replace(/\//g, '_'); return callback(null, { root: name, commonjs2: name, commonjs: name, amd: name, module: name }); } callback(); }); config.externals.push({ '@xa-web/hua-design-vue3': { root: 'huad', // root global variable commonjs2: '@xa-web/hua-design-vue3', // module.exports = xxx commonjs: '@xa-web/hua-design-vue3', // exports[“Library”] = xxx amd: '@xa-web/hua-design-vue3', // define(["xxx"], factory) module: '@xa-web/hua-design-vue3' } });
}
externalDep(config);
module.exports = config; `
能否提供一个最小复现,看起来可能和 tree shaking 有关,仅看配置文件无法定位问题
css 打包出来存在一堆乱码的东西,导致模块丢失无法加载,排查了很久才发现是 css 打包出问题了,换回 1.0.0-alpha.5 就没问题,已经几个月了这个问题还没解决 scss 配置如下
乱码问题看起来是一个独立的问题,可以单开一个新的 issue,并提供最小复现以协助排查
System Info
Details
利用rspack获批构建的打包产物,存在 webpack_require中加载了在 webpack_modules不存在的模块导致代码报错
报错信息 buildQuickly.all.min.js:52 Uncaught TypeError: Cannot read properties of undefined (reading 'call') at webpack_require (buildQuickly.all.min.js:52:700772) at 3580 (buildQuickly.all.min.js:52:59513) at webpack_require (buildQuickly.all.min.js:52:700772) at buildQuickly.all.min.js:52:743628 at buildQuickly.all.min.js:56:128664 at buildQuickly.all.min.js:56:128687 at buildQuickly.all.min.js:1:201 at buildQuickly.all.min.js:1:205
return webpack_modules[t].call(n.exports, n, n.exports, webpack_require),
Reproduce link
No response
Reproduce Steps
1,npm run build 产物在其他系统中试用