基於webpack 4靜態資源打包壓縮配置

2021-09-29 08:10:43 字數 1174 閱讀 9986

1. 實現靜態資源js/css/less的打包、壓縮;

2. html檔案載入對應的js/css/img檔案;

工程目錄結構如下:

使用webpack4 涉及到的檔案配置如下 :

,

"author": "jagger",

"license": "isc",

"devdependencies":

}

const path = require ('path');

// html 打包外掛程式

const htmlplugin = require('html-webpack-plugin');

// css分離與路徑處理外掛程式

const extracttextplugin = require('extract-text-webpack-plugin');

// css壓縮優化

const optimizecss = require('optimize-css-assets-webpack-plugin');

const = require("clean-webpack-plugin");

var website =

module.exports = ,

// 輸出檔案

output: ,

// 模式

mode:'production', //development production

module: ,

,use:

})},

,],fallback: 'style-loader'

})},

}] },]},

plugins:[

new cleanwebpackplugin(), // 每次清除已生成

new htmlplugin(),

new htmlplugin(),

new extracttextplugin(

}),new optimizecss(

}]},

canprint: true

})],

devserver:

}

webpack4配置詳解

方式一 單檔案寫法 entry 方式二 多檔案寫法 entry output 常用的有三種 模板描述 hash模組識別符號的hash,一般應用於filename name hash js chunkhash按需載入塊內容的hash,根據chunk自身的內容計算而來,js name chunkhash...

webpack4快速上手

1.在專案根目錄cnpm init y初始化。生成package.json檔案 2.在專案裡面使用cnpm安裝webpack 3.需要在根目錄下新建webpack.config.js檔案 在其裡面配置暴露物件 module.exports 4.在根目錄下新建src index.js檔案 因為此時執行...

webpack4 基本使用

webpack是基於node構建,所以wepack支援所有node api和語法。即 chrome瀏覽器能支援的ecmascript語法 排除dom bom wbpack都能支援。chrome不支援es6,所以webpack也不支援。建立基本的webpack4.x專案 建立後的目錄 其中 packa...