Skip to content

Commit

Permalink
chore: lastIndexOf
Browse files Browse the repository at this point in the history
  • Loading branch information
1198994985 committed Feb 27, 2024
1 parent 1abb5d9 commit 3dc48e4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default async function ImportCustomerComponentLoader(this: LoaderContext<
let dirName = entryPath.replace(path.extname(entryPath), '');
// 提取npm名称
if (dirName.includes(NODE_MODULES)) {
dirName = dirName.slice(dirName.indexOf(NODE_MODULES) + NODE_MODULES.length + 1);
dirName = dirName.slice(dirName.lastIndexOf(NODE_MODULES) + NODE_MODULES.length + 1);
requestType = NODE_MODULES;
} else if (alias) {
for (const i in alias) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ export const genMiniComponentEntry = (
) => {
entryPath = entryPath.replace(path.extname(entryPath), '');
if (monaStore.nativeEntryMap.has(entryPath)) {

return monaStore.nativeEntryMap.get(entryPath)! as MiniComponentEntry;
} else {

const nEntry = nativeEntry || new MiniComponentEntry(configHelper, entryPath);
monaStore.nativeEntryMap.set(entryPath, nEntry);
return nEntry;
Expand Down Expand Up @@ -74,7 +76,7 @@ export class MiniEntry {
get context() {
let context = this.dirPath;
if (this.dirPath.includes(NODE_MODULES)) {
context = context.slice(0, context.indexOf(NODE_MODULES) + NODE_MODULES.length + 1);
context = context.slice(0, context.lastIndexOf(NODE_MODULES) + NODE_MODULES.length + 1);
}

return context;
Expand All @@ -85,7 +87,7 @@ export class MiniEntry {
let outputPath = path.relative(dirPath, this.dirPath);

if (this.dirPath.includes(NODE_MODULES)) {
outputPath = this.dirPath.slice(this.dirPath.indexOf(NODE_MODULES) + NODE_MODULES.length);
outputPath = this.dirPath.slice(this.dirPath.lastIndexOf(NODE_MODULES) + NODE_MODULES.length);
outputPath = path.join(NPM_DIR, outputPath);
} else if (!this.dirPath.startsWith(dirPath)) {
const dirname = path.basename(this.dirPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ function createTtmlRules(webpackConfig: Config, _configHelper: ConfigHelper) {
useRelativePath: true,
name: path.join(namePrefix, '[path][name].ttml'),
context: dir,
outputPath: (url: string) => {
if (url && url.includes('node_modules')) {
const outputPath1 = url.slice(url.lastIndexOf(NODE_MODULES) + NODE_MODULES.length);
return path.join(namePrefix, outputPath1);
}
return url;
},
});

ttmlRule.use('ttmlLoader').loader(path.resolve(__dirname, '../../plugins/loaders/miniTemplateLoader'));
Expand Down Expand Up @@ -117,8 +124,12 @@ function createCssRule(webpackConfig: Config, configHelper: ConfigHelper) {
postcssOptions: {
plugins: [
pxtOptions.enabled
?
[require.resolve('@bytedance/mona-manager-plugins-shared/dist/plugins/postcss/PostcssPxtransformer/index.js'), pxtOptions]
? [
require.resolve(
'@bytedance/mona-manager-plugins-shared/dist/plugins/postcss/PostcssPxtransformer/index.js',
),
pxtOptions,
]
: null,
].filter(p => p),
},
Expand Down

0 comments on commit 3dc48e4

Please sign in to comment.