最小化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"
                    }
                ]
            }
        ]
    }
    
}

 

转载于:https://www.cnblogs.com/Netsharp/p/10137515.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值