fix(web): generate .swcrc file with modern defaults when creating new webapps (#18749)
This commit is contained in:
parent
791171e95d
commit
750f485b93
@ -77,7 +77,7 @@ describe('Web Components Applications', () => {
|
|||||||
customElements.define('app-root', AppElement);
|
customElements.define('app-root', AppElement);
|
||||||
`
|
`
|
||||||
);
|
);
|
||||||
runCLI(`build ${appName} --outputHashing none --compiler babel`);
|
runCLI(`build ${appName} --outputHashing none`);
|
||||||
checkFilesExist(
|
checkFilesExist(
|
||||||
`dist/apps/${appName}/index.html`,
|
`dist/apps/${appName}/index.html`,
|
||||||
`dist/apps/${appName}/runtime.js`,
|
`dist/apps/${appName}/runtime.js`,
|
||||||
|
|||||||
@ -967,6 +967,17 @@ describe('app', () => {
|
|||||||
'swc-loader': expect.any(String),
|
'swc-loader': expect.any(String),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should add .swcrc when --compiler=swc', async () => {
|
||||||
|
await applicationGenerator(appTree, {
|
||||||
|
...schema,
|
||||||
|
compiler: 'swc',
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(readJson(appTree, '/apps/my-app/.swcrc')).toEqual({
|
||||||
|
jsc: { target: 'es2016' },
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('--root-project', () => {
|
describe('--root-project', () => {
|
||||||
|
|||||||
@ -79,39 +79,34 @@ export function createApplicationFiles(host: Tree, options: NormalizedSchema) {
|
|||||||
: undefined,
|
: undefined,
|
||||||
].filter(Boolean),
|
].filter(Boolean),
|
||||||
});
|
});
|
||||||
} else if (
|
} else if (options.compiler === 'swc') {
|
||||||
options.style === 'styled-components' ||
|
const swcrc: any = {
|
||||||
options.style === '@emotion/styled' ||
|
|
||||||
options.style === 'styled-jsx'
|
|
||||||
) {
|
|
||||||
writeJson(
|
|
||||||
host,
|
|
||||||
`${options.appProjectRoot}/.swcrc`,
|
|
||||||
|
|
||||||
{
|
|
||||||
jsc: {
|
jsc: {
|
||||||
experimental: {
|
target: 'es2016',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
if (options.style === 'styled-components') {
|
||||||
|
swcrc.jsc.experimental = {
|
||||||
plugins: [
|
plugins: [
|
||||||
options.style === 'styled-components'
|
[
|
||||||
? [
|
|
||||||
'@swc/plugin-styled-components',
|
'@swc/plugin-styled-components',
|
||||||
{
|
{
|
||||||
displayName: true,
|
displayName: true,
|
||||||
ssr: true,
|
ssr: true,
|
||||||
},
|
},
|
||||||
]
|
],
|
||||||
: undefined,
|
],
|
||||||
options.style === 'styled-jsx'
|
};
|
||||||
? ['@swc/plugin-styled-jsx', {}]
|
} else if (options.style === '@emotion/styled') {
|
||||||
: undefined,
|
swcrc.jsc.experimental = {
|
||||||
options.style === '@emotion/styled'
|
plugins: [['@swc/plugin-emotion', {}]],
|
||||||
? ['@swc/plugin-emotion', {}]
|
};
|
||||||
: undefined,
|
} else if (options.style === 'styled-jsx') {
|
||||||
].filter(Boolean),
|
swcrc.jsc.experimental = {
|
||||||
},
|
plugins: [['@swc/plugin-styled-jsx', {}]],
|
||||||
},
|
};
|
||||||
}
|
}
|
||||||
);
|
writeJson(host, `${options.appProjectRoot}/.swcrc`, swcrc);
|
||||||
}
|
}
|
||||||
} else if (options.bundler === 'rspack') {
|
} else if (options.bundler === 'rspack') {
|
||||||
generateFiles(
|
generateFiles(
|
||||||
|
|||||||
@ -586,6 +586,9 @@ describe('app', () => {
|
|||||||
};
|
};
|
||||||
"
|
"
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
expect(tree.exists('apps/my-app/.babelrc')).toBeTruthy();
|
||||||
|
expect(tree.exists('apps/my-app/.swcrc')).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should support swc compiler', async () => {
|
it('should support swc compiler', async () => {
|
||||||
@ -609,6 +612,9 @@ describe('app', () => {
|
|||||||
};
|
};
|
||||||
"
|
"
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
expect(tree.exists('apps/my-app/.babelrc')).toBeFalsy();
|
||||||
|
expect(tree.exists('apps/my-app/.swcrc')).toBeTruthy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import {
|
|||||||
Tree,
|
Tree,
|
||||||
updateNxJson,
|
updateNxJson,
|
||||||
updateProjectConfiguration,
|
updateProjectConfiguration,
|
||||||
|
writeJson,
|
||||||
} from '@nx/devkit';
|
} from '@nx/devkit';
|
||||||
import { swcCoreVersion } from '@nx/js/src/utils/versions';
|
import { swcCoreVersion } from '@nx/js/src/utils/versions';
|
||||||
import type { Linter } from '@nx/linter';
|
import type { Linter } from '@nx/linter';
|
||||||
@ -312,12 +313,24 @@ export async function applicationGenerator(host: Tree, schema: Schema) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (options.compiler === 'swc') {
|
if (options.compiler === 'swc') {
|
||||||
|
writeJson(host, joinPathFragments(options.appProjectRoot, '.swcrc'), {
|
||||||
|
jsc: {
|
||||||
|
parser: {
|
||||||
|
syntax: 'typescript',
|
||||||
|
},
|
||||||
|
target: 'es2016',
|
||||||
|
},
|
||||||
|
});
|
||||||
const installTask = addDependenciesToPackageJson(
|
const installTask = addDependenciesToPackageJson(
|
||||||
host,
|
host,
|
||||||
{},
|
{},
|
||||||
{ '@swc/core': swcCoreVersion, 'swc-loader': swcLoaderVersion }
|
{ '@swc/core': swcCoreVersion, 'swc-loader': swcLoaderVersion }
|
||||||
);
|
);
|
||||||
tasks.push(installTask);
|
tasks.push(installTask);
|
||||||
|
} else {
|
||||||
|
writeJson(host, joinPathFragments(options.appProjectRoot, '.babelrc'), {
|
||||||
|
presets: ['@nx/js/babel'],
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setDefaults(host, options);
|
setDefaults(host, options);
|
||||||
|
|||||||
@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"presets": [
|
|
||||||
"@nx/js/babel"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user