我正在更新应用程序,因此它更易于维护。该应用程序当前使用带有许多JS类的非常大的JS文件。我有单独的代码,因此每个JS类都在其自己的JS文件中。我想使用Parcel将所有JS文件合并为一个我可以从index.html
链接到的JS文件。
我已将export default
添加到每个主类。例如。 export default class MyJSClass
。然后,根据需要从index.js
文件(例如import MyJSClass from './MyJSClass.js';
我正在更新的应用程序使用具有以下结构的框架:
resources
|-Public
|-JS
|-singleHugeJSFile.js
|-Templates
|-index.html
我想使用包裹并保留相同的结构,例如
resources
|-Public
|-JS
|-index.js // Entry point JS file
|-MyJSClass.js
|-SomeOtherClass.js
|-AnotherClass.js
...
|-Templates
|-index.html
我已经在资源目录上安装了包裹并运行:
parcel build public/js/index.js
但是这会在dist目录上生成文件。
如何使用Parcel生成包含所有JS的单个入口JS文件并保持应用程序的结构相同,以便我可以继续使用默认路径从index.html链接到此JS?
包裹不支持此功能,但是我已经为此开发了一个插件。签出https://www.npmjs.com/package/parcel-plugin-custom-dist-structure
它适用于所有类型的Web /节点开发项目,它将生成您指定的dist结构,同时也处理导入。
在您的情况下,您将提供给我的插件的配置如下所示:
"customDistStructure": {
"config": {
".js": "Public/JS",
".html": "Templates"
},
"options": {
"development": true
}
}
让我知道您的想法!