webpack.base.conf.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. const path = require('path');
  2. const webpack = require('webpack');
  3. const vueLoaderConfig = require('./vue-loader.conf');
  4. const { IS_DEV, styleRule } = require('./utils');
  5. const DIST = 'dist';
  6. const definePlugin = new webpack.DefinePlugin({
  7. 'process.env': {
  8. NODE_ENV: JSON.stringify(process.env.NODE_ENV),
  9. // DEBUG: IS_DEV ? 'true' : 'false', // whether to log message errors
  10. DEBUG: 'false',
  11. // CLIENT may be `chrome`, `firefox`, `edge`
  12. CLIENT: JSON.stringify(process.env.CLIENT || 'chrome'),
  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. 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: /\.(js|vue)$/,
  42. // loader: 'eslint-loader',
  43. // enforce: 'pre',
  44. // include: [resolve('src'), resolve('test')],
  45. // options: {
  46. // formatter: require('eslint-friendly-formatter')
  47. // }
  48. // },
  49. {
  50. test: /\.vue$/,
  51. loader: 'vue-loader',
  52. options: vueLoaderConfig
  53. },
  54. {
  55. test: /\.js$/,
  56. loader: 'babel-loader',
  57. include: [resolve('src'), resolve('test')]
  58. },
  59. styleRule({ fallback: 'vue-style-loader' }),
  60. ],
  61. },
  62. // cheap-module-eval-source-map is faster for development
  63. devtool: IS_DEV ? '#inline-source-map' : false,
  64. plugins: [
  65. definePlugin,
  66. ],
  67. };