zoukankan      html  css  js  c++  java
  • 最小化webpack项目

    先把代码贴出来,以后慢慢加说明

    参考资料:入门 Webpack,看这篇就够了 / webpack 搭建自动打开,刷新浏览器

    一.功能代码
    1.index.html

    <!DOCTYPE html>
    <html>
      <head>
        <title>bootstrap demo</title>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
      </head>
      <body>
        <script src="bundle.js"></script>
      </body>
    </html>

    2.style.css

    p{color:red}

    3.helper.js

    import "./style.css";
    
    export default function(){
    
        let p = document.createElement("p");
        p.textContent="hello world  "
    
        return p;
    }

    4.index.js

    import text from "./helper.js";
    
    document.body.appendChild(text()); 

    二.package.json

    {
      "name": "indie-grow",
      "version": "0.2.0",
      "description": "indie monitor and dashbord",
      "main": "index.js",
      "scripts": {
        "test": "test",
        "start": "webpack-dev-server --hot --inline",
        "hello": "echo npm says hello!!!!!!",
        "server": "webpack-dev-server --open"
      },
      "keywords": [
        "indie"
      ],
      "author": "schneider",
      "license": "ISC",
      "devDependencies": {
        "open-browser-webpack-plugin": "0.0.5",
        "webpack": "^4.27.1",
        "webpack-cli": "^3.1.2",
        "webpack-dev-server": "^3.1.10"
      },
      "dependencies": {
        "bootstrap": "^4.1.3",
        "jquery": "^3.3.1",
        "popper.js": "^1.14.3"
      }
    }

    三.webpack.config.js

    var webpack = require('webpack');
    
    var OpenBrowserPlugin = require('open-browser-webpack-plugin')
    
    module.exports={
        devtool: 'eval-source-map',
        entry : __dirname + "/index.js",
        output : {
            path : __dirname,
            filename : "bundle.js"
        },
    
        devServer: {
            port:80,
            contentBase: ".",
            historyApiFallback: true,
            inline: true
          } ,
    
          plugins: [ 
            new OpenBrowserPlugin({ url: 'http://localhost:80' }) 
        ],
        module: {
            rules:[
                {
                    test: /.css$/,
                    use: [
                        {
                            loader: "style-loader"
                        }, 
                        {
                            loader: "css-loader"
                        }
                    ]
                }
            ]
        }
        
    }
  • 相关阅读:
    怎么快速掌握一门新技术
    Linq相关
    C# 参数按照ASCII码从小到大排序(字典序)
    测试工具
    sql 创建临时表
    sql行合并
    WCF相关
    免费开源分布式系统日志收集框架 Exceptionless
    VPS,虚拟主机,云主机,独立服务器区别
    c# Dictionary的遍历和排序
  • 原文地址:https://www.cnblogs.com/Netsharp/p/10137515.html
Copyright © 2011-2022 走看看