[英]symfony webpack encore huge js files with datatables
我不知道如何在symfony項目4上通過webpack-encore優化由webpack編譯的.js文件的大小
這是我的布局資產/js/app.js的js:
require('../css/app.css');
require('bootstrap/js/dist/index.js');
我的頁面Assets / js / datatables.js的js:
require('../css/datatables.css');
require('datatables.net-bs4/js/dataTables.bootstrap4.js');
global.$ = $;
和webpack配置文件webpack.config.js:
const Encore = require('@symfony/webpack-encore');
Encore
.setOutputPath('public/build/')
.setPublicPath('/build')
.addEntry('js/app', './assets/js/app.js')
.addEntry('js/datatables', './assets/js/datatables.js')
.cleanupOutputBeforeBuild()
.enableBuildNotifications()
.enableSourceMaps(!Encore.isProduction())
.enableVersioning(Encore.isProduction())
.enableSassLoader()
.autoProvidejQuery()
;
module.exports = Encore.getWebpackConfig();
注意datatables.js文件的大小...。
$ ls -lah public/build/js/
total 3.2M
drwxr-xr-x 3 dev dev 4.0K Aug 16 12:52 .
drwxr-xr-x 5 dev dev 4.0K Aug 16 12:52 ..
-rw-r--r-- 1 dev dev 470K Aug 16 12:52 app.css
-rw-r--r-- 1 dev dev 740K Aug 16 12:52 app.js
-rw-r--r-- 1 dev dev 14K Aug 16 12:52 datatables.css
-rw-r--r-- 1 dev dev 2.0M Aug 16 12:52 datatables.js
drwxr-xr-x 2 dev dev 4.0K Aug 16 12:52 default
2.0M:這對於數據表來說似乎過多
結束本次討論:為生產環境進行編譯確實可以大大減少文件的大小。 這是另一個解決方案,請使用SharedEntries:
const Encore = require('@symfony/webpack-encore');
Encore
.setOutputPath('public/build/')
.setPublicPath('/build')
.createSharedEntry('js/app', './assets/js/app.js')
.addEntry('js/datatables', './assets/js/datatables.js')
.cleanupOutputBeforeBuild()
.enableBuildNotifications()
.enableSourceMaps(!Encore.isProduction())
.enableVersioning(Encore.isProduction())
.enableSassLoader()
.autoProvidejQuery();
const config = Encore.getWebpackConfig();
delete config.stats;
module.exports = config;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.