webpack.base.conf.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. const path = require('path');
  2. const webpack = require('webpack');
  3. const MinifyPlugin = require('babel-minify-webpack-plugin');
  4. const minifyPreset = require('babel-preset-minify');
  5. const vueLoaderConfig = require('./vue-loader.conf');
  6. const { IS_DEV, styleRule, definitions } = require('./utils');
  7. // const { MINIFY } = process.env;
  8. const MINIFY = true;
  9. const DIST = 'dist';
  10. const definePlugin = new webpack.DefinePlugin(definitions);
  11. function resolve(dir) {
  12. return path.join(__dirname, '..', dir);
  13. }
  14. module.exports = {
  15. output: {
  16. path: resolve(DIST),
  17. publicPath: '/',
  18. filename: '[name].js',
  19. },
  20. resolve: {
  21. // Tell webpack to look for peer dependencies in `node_modules`
  22. // when packages are linked from outside directories
  23. modules: [resolve('node_modules')],
  24. extensions: ['.js', '.vue'],
  25. alias: {
  26. src: resolve('src'),
  27. }
  28. },
  29. node: {
  30. // css-loader requires unnecessary `Buffer` polyfill,
  31. // which increases the bundle size significantly.
  32. // See:
  33. // - https://github.com/webpack-contrib/css-loader/issues/454
  34. // - https://github.com/vuejs/vue-loader/issues/720
  35. Buffer: false,
  36. },
  37. module: {
  38. rules: [
  39. {
  40. test: /\.vue$/,
  41. loader: 'vue-loader',
  42. options: vueLoaderConfig
  43. },
  44. {
  45. test: /\.js$/,
  46. loader: 'babel-loader',
  47. include: [resolve('src'), resolve('test')]
  48. },
  49. styleRule({
  50. fallback: 'vue-style-loader',
  51. loaders: ['postcss-loader'],
  52. }),
  53. ],
  54. },
  55. // cheap-module-eval-source-map is faster for development
  56. devtool: IS_DEV ? '#inline-source-map' : false,
  57. plugins: [
  58. definePlugin,
  59. !IS_DEV && new MinifyPlugin({
  60. mangle: !!MINIFY,
  61. }, {
  62. babili: (...args) => Object.assign(minifyPreset(...args), {
  63. minified: !!MINIFY,
  64. compact: !!MINIFY,
  65. }),
  66. }),
  67. ].filter(Boolean),
  68. };