简体   繁体   English

如何使用Webpack将非混乱的javascript文件捆绑到文件中

[英]how to bundle non mudular javascript file into a file using webpack

I want to bundle a file which is non modular js, it use jquery, register a method on $.fn, so this js must behind jquery after bundled. 我想捆绑一个非模块化js的文件,它使用jquery,在$ .fn上注册一个方法,因此此js在捆绑后必须位于jquery之后。

this js file like 这个js文件像

(function($){
     $.fn.splitPane = ...
}(JQuery)

complete code split-pane.js 完整的代码split-pane.js

all relative file I think will be useful to solve this problem. 我认为所有相关文件都将有助于解决此问题。 https://gist.github.com/iamwwc/4e048d8669c332cecee2233f850c69d4 https://gist.github.com/iamwwc/4e048d8669c332cecee2233f850c69d4

my project path: 我的项目路径:

/root
    /dist/public/assets/js/main.js  #it's bundled result file.
    /src/main.ts
    /vendor/split-pane.js
package.json
tsconfig.json
webpack.config.js

I think in result main.js, ideal order is jquery => split-pane => main.ts. 我认为在结果main.js中,理想的顺序是jquery => split-pane =>main.ts。 I use raw-loader to load split-pane after jquery, but not working. 我使用raw-loader在jquery之后加载拆分窗格,但无法正常工作。

please help me.. I used Google, stackoverflow, webpack docs and lots of methods to solve this problem, but all are not working. 请帮助我。.我使用了Google,stackoverflow,webpack docs和许多方法来解决此问题,但是所有方法都无法正常工作。 I'm tired. 我累了。

finally, forgive my bad English. 最后,请原谅我的英语不好。

At the top of split-pane.js, add var jQuery = require('jquery') . 在split-pane.js的顶部,添加var jQuery = require('jquery') Then do require('./vendor/split-pane.js') when you want to use it. 然后在require('./vendor/split-pane.js')时使用它。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM