Skip to content

Specify output filename in production build using webpack. #501

Closed
@williamsharkey

Description

@williamsharkey

I want to specify the filename for a production build of a vue.js project that uses webpack, so that the bundled js file is not dynamically named client.[hash].js, but helloworld.js.

I created the project using vue init

Currently it outputs the following:

  • index.html
  • client.c4113ffa.js
  • client.c4113ffa.js.map

I used the command:
vue build src/main.js --prod

My webpack.config.js file is listed below. I added the a line near the end, expecting that it would output helloworld.js, but it had no effect. I saw an issue that I think address this issue, but I am unsure of how to take advantage of it ( #326 )

I apologize if I am posting this issue in the wrong place, perhaps it is an issue with UglifyJS?


var path = require('path')
var webpack = require('webpack')

module.exports = {
  entry: './src/main.js',
  output: {
    path: path.resolve(__dirname, './dist'),
    publicPath: '/dist/',
    filename: 'build.js'
  },
  module: {
    rules: [
      {
        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'
    }
  },
  devServer: {
    historyApiFallback: true,
    noInfo: true
  },
  performance: {
    hints: false
  },
  devtool: '#eval-source-map'
}

if (process.env.NODE_ENV === 'production') {
  module.exports.devtool = '#source-map'

//ADDED THIS START
  module.exports.output.filename= 'helloworld.js'
//ADDED THIS END



    // 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
      })
    ])
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions