我开始使用 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(),
]
}
你知道我做错了什么吗?
呼啦一阵风
相关分类