资讯专栏INFORMATION COLUMN

vue.js多页面开发 webpack.config.js 配置方式

史占广 / 1994人阅读

摘要:配置文件代码得到入口文件源文件目录目录如下每个文件夹下的文件都会打包文件夹为组件生成多个入口文件

配置文件代码

var path = require("path")
var webpack = require("webpack")
var glob = require("glob");

得到入口文件

// 源文件目录
var sSystem = "src/";
// src目录如下

每个文件夹下的.js文件都会打包
components文件夹为组件
// 生成多个入口文件
function getEntry() {

var entry = {};
var nLength = sSystem.length - 1;
var srcDirName = "./" + sSystem + "/**/*.js";

glob.sync(srcDirName).forEach(function (name) {
    //name:./src/ovdream/basic/member/index/index.js
    var n = name.slice(name.lastIndexOf(sSystem) + nLength, name.length - 3);
    //n:/member/index/index
    entry[n] = name;

});
return entry;

}

exports

module.exports = {

entry: getEntry(),
output: {
    path: path.resolve(__dirname, "./dist"),
    publicPath: "/dist/",
    filename: "[name].js"
},
module: {
    rules: [
      {
          test: /.css$/,
          use: [
            "vue-style-loader",
            "css-loader"
          ],
      },
      {
          test: /.vue$/,
          loader: "vue-loader",
          options: {
              loaders: {
                  // Since sass-loader (weirdly) has SCSS as its default parse mode, we map
                  // the "scss" and "sass" values for the lang attribute to the right configs here.
                  // other preprocessors should work out of the box, no loader config like this necessary.
              }
              // other vue-loader options go here
          }
      },
      {
          test: /.js$/,
          loader: "babel-loader",
          exclude: /node_modules/
      },
      {
          test: /.(png|jpg|gif|svg)$/,
          loader: "file-loader",
          options: {
              name: "[name].[ext]?[hash]"
          }
      }
    ]
},
resolve: {
    alias: {
        "vue$": "vue/dist/vue.esm.js"
    },
    extensions: ["*", ".js", ".vue", ".json"]
},
devServer: {
    historyApiFallback: true,
    noInfo: true,
    overlay: true
},
performance: {
    hints: false
},
devtool: "#eval-source-map"

}
if (process.env.NODE_ENV === "production") {

module.exports.devtool = "#source-map"
// http://vue-loader.vuejs.org/en/workflow/production.html
module.exports.plugins = (module.exports.plugins || []).concat([
  new webpack.DefinePlugin({
      "process.env": {
          NODE_ENV: ""production""
      }
  }),
  new webpack.optimize.UglifyJsPlugin({
      sourceMap: true,
      compress: {
          warnings: false
      }
  }),
  new webpack.LoaderOptionsPlugin({
      minimize: true
  })
])

}

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/108317.html

相关文章

  • 基于webpack4的VUE页脚手架

    摘要:另外备注一部分参数的说明折叠有助于文档树中文本节点的空白区域对进行压缩默认默认按照不同文件的依赖关系来排序。敲黑板讲重点的当然目前这部分的文档在官网还不是很全,所以这里我们参考了印记中文的说明文档,指优化模块。 链接 写在前面 为什么要自己手写一个脚手架? 如何去思考遇到的问题? 正文 链接 原文链接 github whale-vue ——写在前面 1、为什么要自己手写...

    张金宝 评论0 收藏0
  • vue开发看这篇文章就够了

    摘要:注意此处获取的数据是更新后的数据,但是获取页面中的元素是更新之前的钩子函数说明组件已经更新,所以你现在可以执行依赖于的操作。钩子函数说明实例销毁 Vue -渐进式JavaScript框架 介绍 vue 中文网 vue github Vue.js 是一套构建用户界面(UI)的渐进式JavaScript框架 库和框架的区别 我们所说的前端框架与库的区别? Library 库,本质上是一...

    fsmStudy 评论0 收藏0
  • webpack使用记录

    容易混淆概念解析 读这篇文章理清下面概念 webpack 中那些最易混淆的 5 个知识点 1.module,chunk 和 bundle 的区别是什么?2.filename 和 chunkFilename 的区别 版本区别 webpack 2x entry output loaders file-loader:把文件输出到一个文件夹中,在代码中通过相对 URL 去引用输出的文件 url-lo...

    Sike 评论0 收藏0
  • 简单vue项目脚手架

    摘要:简单项目脚手架地址使用技术栈需要学习的知识内容相当多,尤其是教程,官方脚手架虽然相当完整齐全,但是修改起来还是挺花时间,于是自己参照网上的资料和之前做过的项目用到的构建工具地去写了一个简单项目脚手架。 简单vue项目脚手架 github地址 使用技术栈 webpack(^2.6.1) webpack-dev-server(^2.4.5) vue(^2.3.3) vuex(^2.3.1...

    opengps 评论0 收藏0

发表评论

0条评论

史占广

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<