我想知道是否可以将所有内容放在app.js文件中?我有很多文件,我不会长时间触摸,所以我不需要担心缓存。
现在我在webpack.mix.js中执行此操作:
mix.js('resources/assets/js/app.js', 'public/js') .sass('resources/assets/sass/app.scss', 'public/css') .scripts([ 'resources/assets/js/libs/xxxx.js', 'resources/assets/js/libs/xxxx.js', 'resources/assets/js/libs/xxxx.js', 'resources/assets/js/libs/xxxx.js', 'resources/assets/js/libs/xxxx.js', 'resources/assets/js/libs/xxxx.js', 'resources/assets/js/libs/xxxx.js', 'resources/assets/js/libs/xxxx.js' ], 'public/js/all.js');
这将生成两个JS文件: app.js 和 all.js 。我现在想要做的是将这些文件合并到一个大文件app.js.这是可能的吗?:
mix.babel(['app.js', 'all.js'], 'app.js');
?
答案 0 :(得分:0)
您可以将所有内容都放在js()
方法中并利用它(如here所述):
mix.sass('resources/assets/sass/app.scss', 'public/css');
mix.js([
'resources/assets/js/app.js',
'resources/assets/js/libs/xxxx.js',
'resources/assets/js/libs/xxxx.js',
'resources/assets/js/libs/xxxx.js',
'resources/assets/js/libs/xxxx.js',
'resources/assets/js/libs/xxxx.js',
'resources/assets/js/libs/xxxx.js',
'resources/assets/js/libs/xxxx.js',
'resources/assets/js/libs/xxxx.js'
], 'public/js/all.js');
尝试检查the documentation from the Laravel Mix repository on Github。有一些有用的信息和例子。
答案 1 :(得分:0)
要合并.js文件,请使用mix.combine:
mix.combine(['one.js', 'two.js'], 'merged.js');
https://github.com/JeffreyWay/laravel-mix/blob/master/docs/concatenation-and-minification.md