webpack.base.conf.js 2.0 KB

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