webpack.base.conf.js 1.9 KB

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