Skip to content

Commit

Permalink
enable disableTransformByDefault
Browse files Browse the repository at this point in the history
  • Loading branch information
ahabhgk committed Dec 6, 2023
1 parent 6676ee5 commit 60606ec
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 35 deletions.
21 changes: 8 additions & 13 deletions packages/rspack/src/utils/with-nx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
ExternalItem,
ResolveAlias,
RspackPluginInstance,
rspack,
} from '@rspack/core';
import { LicenseWebpackPlugin } from 'license-webpack-plugin';
import * as path from 'path';
Expand Down Expand Up @@ -58,6 +59,13 @@ export function withNx(_opts = {}) {
);
}

plugins.push(new rspack.CopyRspackPlugin({
patterns: getCopyPatterns(
normalizeAssets(options.assets, context.root, sourceRoot)
),
}));
plugins.push(new rspack.ProgressPlugin())

options.fileReplacements.forEach((item) => {
alias[item.replace] = item.with;
});
Expand Down Expand Up @@ -133,25 +141,12 @@ export function withNx(_opts = {}) {
infrastructureLogging: {
debug: false,
},
builtins: {
copy: {
patterns: getCopyPatterns(
normalizeAssets(options.assets, context.root, sourceRoot)
),
},
progress: {},
},
externals,
externalsType,
stats: {
colors: true,
preset: 'normal',
},
experiments: {
rspackFuture: {
disableTransformByDefault: false
}
}
};

if (options.optimization) {
Expand Down
50 changes: 43 additions & 7 deletions packages/rspack/src/utils/with-react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,51 @@ export function withReact(opts = {}) {
context,
});

const react = {
runtime: 'automatic',
development: isDev,
refresh: isDev,
};

return {
...config,
builtins: {
...config.builtins,
react: {
runtime: 'automatic',
development: isDev,
refresh: isDev,
},
module: {
...config.module,
rules: [
...(config.module.rules || []),
{
test: /\.jsx$/,
loader: 'builtin:swc-loader',
options: {
jsc: {
parser: {
syntax: 'ecmascript',
jsx: true,
},
},
transform: {
react,
},
},
type: 'javascript/auto',
},
{
test: /\.tsx$/,
loader: 'builtin:swc-loader',
options: {
jsc: {
parser: {
syntax: 'typescript',
jsx: true,
},
},
transform: {
react,
},
},
type: 'javascript/auto',
},
],
},
};
};
Expand Down
39 changes: 24 additions & 15 deletions packages/rspack/src/utils/with-web.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Configuration, RuleSetRule } from '@rspack/core';
import { Configuration, RuleSetRule, rspack } from '@rspack/core';
import * as path from 'path';
import { SharedConfigContext } from './model';

Expand Down Expand Up @@ -44,6 +44,19 @@ export function withWeb(opts: WithWebOptions = {}) {
...config.module,
rules: [
...(config.module.rules || []),
{
test: /\.ts$/,
loader: 'builtin:swc-loader',
options: {
jsc: {
parser: {
syntax: 'typescript',
jsx: true,
},
},
},
type: 'javascript/auto',
},
{
test: /\.css$/,
type: opts?.cssModules ? 'css/module' : undefined,
Expand Down Expand Up @@ -98,21 +111,17 @@ export function withWeb(opts: WithWebOptions = {}) {
},
].filter((a): a is RuleSetRule => !!a),
},
builtins: {
...config.builtins,
html: [
...(config.builtins.html || []),
{
template: options.indexHtml
? path.join(context.root, options.indexHtml)
: path.join(projectRoot, 'src/index.html'),
},
],
define: {
...config.builtins.define,
plugins: [
...config.plugins,
new rspack.HtmlRspackPlugin({
template: options.indexHtml
? path.join(context.root, options.indexHtml)
: path.join(projectRoot, 'src/index.html'),
}),
new rspack.DefinePlugin({
'process.env.NODE_ENV': isProd ? "'production'" : "'development'",
},
},
})
],
};
};
}

0 comments on commit 60606ec

Please sign in to comment.