ReferenceError: webpack is not defined

小主早安發表於2020-11-27

剛才引入

 new webpack.BannerPlugin('版權歸牛XX公司所有')

報錯:

[webpack-cli] ReferenceError: webpack is not defined
    at Object.<anonymous> (E:\workplace\vuework\webpack\04-webpack配置vue\webpack.config.js:76:13)
    at Module._compile (E:\workplace\vuework\webpack\04-webpack配置vue\node_modules\v8-compile-cache\v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:690:17)
    at require (E:\workplace\vuework\webpack\04-webpack配置vue\node_modules\v8-compile-cache\v8-compile-cache.js:159:20)
    at requireConfig (E:\workplace\vuework\webpack\04-webpack配置vue\node_modules\webpack-cli\lib\groups\resolveConfig.js:73:18)
    at Array.map (<anonymous>)

處理方法是在檔案的頭部:

const webpack = require('webpack');

在這裡插入圖片描述
檔案尾部再
在這裡插入圖片描述

相關文章