我開始使用 webpack(版本 3),當我嘗試從我的“app.js”文件中使用 jQuery 時,什么也沒有發生:我 npm install --save jquery 和:import $ from 'jquery'$('body').css('backgroundColor', '#DD0000')document.body.style.backgroundColor = "red";當我嘗試使用 document.body.style.backgroundColor = "red"; 更改 CSS 時 它告訴我“無法讀取 null 的屬性樣式”但對于其余的工作,我的意思是我成功地嘗試了這個:import json from "./test"console.log(json)這是我的 HTML 頭部:<head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Webpack</title> <link rel="stylesheet" href="./styles.css"> <script src="./dist/bundle.js"></script></head>這是我的 webpack 配置:const path = require("path");const uglify = require("uglifyjs-webpack-plugin");module.exports = { watch: true, entry: './app.js', output: { path: path.resolve('./dist'), filename: 'bundle.js' }, module: { rules: [ { test: /\.jsx?$/, exclude: /(node_modules|bower_components)/, use: ["babel-loader"], } ] }, plugins: [ new uglify(), ]}你知道我做錯了什么嗎?
Webpack 不能使用 jQuery
當年話下
2022-10-08 10:37:16