Separate js files
See original GitHub issue- Laravel Mix Version: 1.4.2 (
npm list --depth=0
) - Node Version (
node -v
): v7.10.1 - NPM Version (
npm -v
): 5.3.0 - OS: Ubuntu 16.04
Description:
I don’t really understand how webpack works. I fail to make this work, please help.
webpack.mix.js
...
mix.js('resources/assets/js/admin-lte.js', 'public/js')
.sass('resources/assets/sass/admin-lte.scss', 'public/css');
mix.js('resources/assets/js/datatables.net.js', 'public/js')
.sass('resources/assets/sass/datatables.net.scss', 'public/css');
mix.js('resources/assets/js/metrics/index.js', 'public/js/metrics')
.sass('resources/assets/sass/metrics/index.scss', 'public/css/metrics');
...
resources/assets/js/admin-lte.js
require('./bootstrap');
require('fastclick');
require('admin-lte');
require('sparkline');
require('jvectormap');
require('jvectormap/tests/assets/jquery-jvectormap-world-mill-en')
require('slim-scroll');
require('chart.js');
resources/assets/js/datatables.net.js
require('datatables.net')();
require('datatables.net-bs')();
resources/assets/js/metrics/index.js
$(function() {
$('#metrics').DataTable();
});
view file
<script src="{{ mix('/js/admin-lte.js') }}" charset="utf-8"></script>
<script src="{{ mix('/js/datatables.net.js') }}" charset="utf-8"></script>
<script src="{{ mix('/js/metrics/index.js') }}" charset="utf-8"></script>
Not all page using datatable, so the goal is to seprate datatable, but i don’t understand why it’s failed
console log error:
Uncaught TypeError: Cannot set property '$' of undefined
at DataTable (datatables.net.js?id=3df6b5027d25fee26b58:393)
at Object../resources/assets/js/datatables.net.js (datatables.net.js?id=3df6b5027d25fee26b58:25875)
at __webpack_require__ (datatables.net.js?id=3df6b5027d25fee26b58:20)
at Object.1 (datatables.net.js?id=3df6b5027d25fee26b58:25883)
at __webpack_require__ (datatables.net.js?id=3df6b5027d25fee26b58:20)
at datatables.net.js?id=3df6b5027d25fee26b58:63
at datatables.net.js?id=3df6b5027d25fee26b58:66
Issue Analytics
- State:
- Created 6 years ago
- Comments:7
Top Results From Across the Web
How can I split my javascript code into separate files?
Just include the script files and they work as if it was a single file. Javascript doesn't have file scope. Once the code...
Read more >External JavaScript File - Javatpoint
An external JavaScript file must be saved by .js extension. It is recommended to embed all JavaScript files into a single file. It...
Read more >Can I split up large js files into separate files? - Reddit
If you want to split a file into multiple files, you should have a better reason than that. In my opinion, splitting code...
Read more >How to write JavaScript in an External File? - Tutorialspoint
Create external JavaScript file with the extension .js. After creating, add it to the HTML file in the script tag. The src attribute...
Read more >JavaScript Where To - W3Schools
External scripts are practical when the same code is used in many different web pages. JavaScript files have the file extension .js. To...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Okay, seems like i just find the solution. It’s tricky when it comes to jQuery plugin (because it’s not instance new object, but modifying jquery object).
Here is my workaround
resources/assets/js/datatables.net.js
Hope this will help someone. Thanks
hi I wants to compile DataTable as a separate file. So I created files as like below…
resource/js/datatables/datatable.js
resource/js/datatables/datatablePlugins.js
webpack.mix.js
& my View File
But when I run it in Browser then browser console show me this error
Uncaught Unknown button type: print
Please Help me…