简体   繁体   English

如何从npm包中请求替代js文件而不指定完整的node_modules路径

[英]How to require an alternative js file from a npm package without specifiying full node_modules path

I am using the ES2016 import syntax to load the select2 libray from an npm module (via Webpack): 我使用ES2016导入语法从npm模块加载select2 libray(通过Webpack):

import 'select2';

This works fine and loads the following file from the node_modules directory. 这很好用,并从node_modules目录加载以下文件。

node_modules/select2/dist/js/select2.js node_modules /选择2 /距离/ JS / select2.js

Now within that directory they have a full version of the library which has some extra functionality I need, it is called: 现在在该目录中,他们有一个完整版本的库,它有一些我需要的额外功能,它被称为:

node_modules/select2/dist/js/select2.full.js node_modules /选择2 /距离/ JS / select2.full.js

Is there a way to import this without providing the full relative path to my node_modules folder? 有没有办法导入这个而不提供我的node_modules文件夹的完整相对路径?

I tried: 我试过了:

import 'select2.full'

but no luck. 但没有运气。

Try this: 试试这个:

import 'select2/dist/js/select2.full.js'

I think this is the best you are going to get. 我认为这是你将获得的最好成绩。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从gulpfile.js中的相对路径要求node_modules - Require node_modules from a relative path in gulpfile.js 使用 require() 从 node_modules 导入 css 文件 - import css file from node_modules using require() Cordova:npm安装后如何从node_modules包含.js .css文件 - Cordova: How to include .js .css files from node_modules after npm install 使用express node js时如何从node_modules导入包 - how can i import package from node_modules when use express node js 图表 v4:找不到模块:错误:Package 路径。 不从 package node_modules/chart.js 导出 - Chart v4 : Module not found: Error: Package path . is not exported from package node_modules/chart.js 如何在不运行require的情况下知道node.js的完整路径 - How can I know the full path node.js will require without running require 如何从node_modules获取节点程序包使用者目录? - How to get node package consumer directory from node_modules? 为什么我的npm package的所有文件都安装在node_modules中? - Why all files of my npm package are installed in node_modules? 如何在docker构建期间的yarn / npm安装期间缓存node_modules以获取未更改的package.json - How to cache node_modules for unchanged package.json during yarn / npm install during docker build? 如何在我的js文件中需要一些npm模块 - how to require some npm modules into my js file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM