2

I'm using vue-cli 2.9.6, and created a vue project using vue init webpack <project name>.

When I call vue run build, it is creating a number of different js files (and names change each time...):

vendor.20d54e752692d648b42a.js
vendor.20d54e752692d648b42a.js.map
app.ed70f310595763347909.js
app.ed70f310595763347909.js.map
manifest.2ae2e69a05c33dfc65f8.js
manifest.2ae2e69a05c33dfc65f8.js.map

And also css files like this:

app.a670fcd1e9a699133143a2b144475068.css
app.a670fcd1e9a699133143a2b144475068.css.map

I would like the output to simply be 2 files:

build.js  { for all js }
styles.css { for all css }

How can I achieve this?

2
  • looking for something like this? dev.to/coolgoose/… Commented Feb 3, 2019 at 23:25
  • Well I don't know how to apply that to the existing webpack.prod.conf.js file that I have. It is easy enough for me to remove the .[chunkhash] clause from the config file, however that will still generate 3 files: vender.js, app.js and manifest.js. How do I combine them to 1 file? Commented Feb 4, 2019 at 0:58

2 Answers 2

4
  1. for preventing creation of vendor.js and manifest.js just remove following code from webpack.prod.conf.js
    // split vendor js into its own file
    new webpack.optimize.CommonsChunkPlugin({
      name: 'vendor',
      minChunks (module) {
        // any required modules inside node_modules are extracted to vendor
        return (
          module.resource &&
          /\.js$/.test(module.resource) &&
          module.resource.indexOf(
            path.join(__dirname, '../node_modules')
          ) === 0
        )
      }
    }),
    // extract webpack runtime and module manifest to its own file in order to
    // prevent vendor hash from being updated whenever app bundle is updated
    new webpack.optimize.CommonsChunkPlugin({
      name: 'manifest',
      minChunks: Infinity
    }),
  1. To prevent sourceMaps set in config/index.js the variable productionSourceMap from true to false

  2. Changing name of app.js to build.js can be obtained modifying the entry and outputproperties in webpack.base.conf.js this way:

entry: {
    build: './src/main.js'
},
output: {
    path: config.build.assetsRoot,
    filename: utils.assetsPath('js/[name].js'),
    chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
},
  1. Update name of the css output file updating options of ExtractTextPluginin webpack.prod.conf.js to filename: utils.assetsPath('css/styles.css'),
Sign up to request clarification or add additional context in comments.

Comments

1

// vue.config.js

module.exports = {
  chainWebpack: config => {
    if(config.plugins.has('extract-css')) {
      const extractCSSPlugin = config.plugin('extract-css')
      extractCSSPlugin && extractCSSPlugin.tap(() => [{
        filename: 'styles.css',
        chunkFilename: 'styles.css'
      }])
    }
  },
  configureWebpack: {
    output: {
      filename: 'build.js',
      chunkFilename: 'build.js'
    }
  }
}

or

module.exports = {
  configureWebpack: {
    optimization: {
      splitChunks: false
    }
  },
  filenameHashing: false
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.