C++列表实现

阅读 14

2024-05-15

优化前

webpack.config.js

const config = {
    entry: './src/index.js',
    output: {
        filename: 'main.js'
    },
  mode: 'development',
}

module.exports = config;
src/index.js
import $ from 'jquery'
$(document).ready(() => {
    $('body').css({
        width: '100%',
        height: '100%',
        'background-color': 'red'
    })
})

在这里插入图片描述

优化后

webpack.config.js

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

const config = {
    entry: './src/index.js',
    output: {
        filename: 'main.js'
    },
  mode: 'development',
  externals: {
    $: 'jQuery'
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: './index.html',
  })
  ]
}

module.exports = config;
src/index.js
$(document).ready(() => {
    $('body').css({
        width: '100%',
        height: '100%',
        'background-color': 'red'
    })
})
index.html
<!DOCTYPE html>
<html lang="en">
<body>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
</body>
</html>

在这里插入图片描述

精彩评论(0)

0 0 举报