webpack.base.conf.js 1.9 KB

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