cli: avoid external dep for node_modules rewrite
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -140,7 +140,6 @@
|
||||
"rollup-plugin-dts": "^6.1.0",
|
||||
"rollup-plugin-esbuild": "^6.1.1",
|
||||
"rollup-plugin-postcss": "^4.0.0",
|
||||
"rollup-plugin-rename-node-modules": "^1.3.1",
|
||||
"rollup-pluginutils": "^2.8.2",
|
||||
"semver": "^7.5.3",
|
||||
"style-loader": "^3.3.1",
|
||||
|
||||
@@ -25,7 +25,6 @@ import svgr from '@svgr/rollup';
|
||||
import dts from 'rollup-plugin-dts';
|
||||
import json from '@rollup/plugin-json';
|
||||
import yaml from '@rollup/plugin-yaml';
|
||||
import renameNodeModules from 'rollup-plugin-rename-node-modules';
|
||||
import {
|
||||
RollupOptions,
|
||||
OutputOptions,
|
||||
@@ -116,10 +115,16 @@ export async function makeRollupConfigs(
|
||||
const output = new Array<OutputOptions>();
|
||||
const mainFields = ['module', 'main'];
|
||||
|
||||
// Avoid using node_modules as a directory name, since it's trimmed from published packages.
|
||||
// This can happen when inlining dependencies such as style-inject added for css injection.
|
||||
const rewriteNodeModules = (name: string) =>
|
||||
name.replaceAll('node_modules', 'node_modules_dist');
|
||||
|
||||
if (options.outputs.has(Output.cjs)) {
|
||||
output.push({
|
||||
dir: distDir,
|
||||
entryFileNames: `[name].cjs.js`,
|
||||
entryFileNames: chunkInfo =>
|
||||
`${rewriteNodeModules(chunkInfo.name)}.cjs.js`,
|
||||
chunkFileNames: `cjs/[name]-[hash].cjs.js`,
|
||||
format: 'commonjs',
|
||||
interop: 'compat',
|
||||
@@ -132,7 +137,8 @@ export async function makeRollupConfigs(
|
||||
if (options.outputs.has(Output.esm)) {
|
||||
output.push({
|
||||
dir: distDir,
|
||||
entryFileNames: `[name].esm.js`,
|
||||
entryFileNames: chunkInfo =>
|
||||
`${rewriteNodeModules(chunkInfo.name)}.esm.js`,
|
||||
chunkFileNames: `esm/[name]-[hash].esm.js`,
|
||||
format: 'module',
|
||||
sourcemap: true,
|
||||
@@ -182,7 +188,6 @@ export async function makeRollupConfigs(
|
||||
include: /\.icon\.svg$/,
|
||||
template: svgrTemplate,
|
||||
}),
|
||||
renameNodeModules('node_modules_dist'),
|
||||
esbuild({
|
||||
target: 'ES2022',
|
||||
minify: options.minify,
|
||||
|
||||
Reference in New Issue
Block a user