为什么在运行npm run build(Vue)时,css和html不会发送到dist文件夹?

时间:2019-07-09 20:35:28

标签: vue.js webpack

当我在dist文件夹中运行npm run build时,我仅获得图像,build.js,build.js.map和嵌入了build.js的Html文件(在安装HtmlWebpackPlugin之后添加)。如何将必要的文件嵌入dist文件夹,以便部署应用程序?

该项目是使用VueCLI通过webpack简单配置初始化的,我不确定这是否是导致问题的原因。我添加了HtmlWebpackPlugin,但这只添加了一个带有基本样板的HTML文件,并嵌入了build.js。

var path = require("path");
var webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");

module.exports = {
  entry: "./src/main.js",
  mode: "development",
  // ...
  plugins: [
    new HtmlWebpackPlugin({
      title: "Output Management"
    })
  ],
  output: {
    path: path.resolve(__dirname, "./dist"),
    publicPath: "/dist/",
    filename: "build.js"
  },
  module: {
    rules: [
      {
        test: /\.css$/,
        use: ["vue-style-loader", "css-loader"]
      },
      {
        test: /\.vue$/,
        loader: "vue-loader",
        options: {
          loaders: {}
          // 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.LoaderOptionsPlugin({
      minimize: true
    })
  ]);
}

0 个答案:

没有答案