webpack.base.conf.js 2.0 KB

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