zoukankan      html  css  js  c++  java
  • [vue]使用webpack打包

    使用webpack打包

    安装

    npm install webpack -g
    npm install webpack-cli -g
    

    hello.js暴露方法

    exports.hello = function () {
        document.write("<h1>hello</h1>");
    }
    

    main.js入口

    var hello = require("./hello");
    hello.hello();
    

    webpack.config.js打包配置

    module.exports = {
      entry: './modules/main.js',
      output: {
          filename: './js/bundle.js'
      }
    };
    

    生成的bundle.js

    !function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){n(1).hello()},function(e,t){t.hello=function(){document.write("<h1>hello</h1>")}}]);
    

    index.html导入生成的包即可

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    
    <script src="dist/js/bundle.js"></script>
    </body>
    </html>
    
  • 相关阅读:
    写文件
    CI使用数据库
    ajxa方法
    find---查找文件或目录
    diff---比较文件不同
    ifup&&ifdown --- 激活/关闭指定的网络接口。
    ifconfig---配置和显示Linux内核中网络接口
    ssh-agent && 及 ssh-add介绍
    host---域名查询
    tracepath---追踪并显示报文到达目的主机所经过的路由信息。
  • 原文地址:https://www.cnblogs.com/pinked/p/12320212.html
Copyright © 2011-2022 走看看