webpack.base.conf.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. var path = require('path')
  2. var config = require('../config')
  3. var utils = require('./utils')
  4. var projectRoot = path.resolve(__dirname, '../')
  5. var env = process.env.NODE_ENV
  6. // check env & config/index.js to decide whether to enable CSS source maps for the
  7. // various preprocessor loaders added to vue-loader at the end of this file
  8. var cssSourceMapDev = (env === 'development' && config.dev.cssSourceMap)
  9. var cssSourceMapProd = (env === 'production' && config.build.productionSourceMap)
  10. var useCssSourceMap = cssSourceMapDev || cssSourceMapProd
  11. module.exports = {
  12. entry: {
  13. app: './src/main.js'
  14. },
  15. output: {
  16. path: config.build.assetsRoot,
  17. publicPath: process.env.NODE_ENV === 'production' ? config.build.assetsPublicPath : config.dev.assetsPublicPath,
  18. filename: '[name].js'
  19. },
  20. resolve: {
  21. extensions: ['', '.js', '.vue', '.json'],
  22. fallback: [path.join(__dirname, '../node_modules')],
  23. alias: {
  24. 'vue$': 'vue/dist/vue.common.js',
  25. 'src': path.resolve(__dirname, '../src'),
  26. 'assets': path.resolve(__dirname, '../src/assets'),
  27. 'components': path.resolve(__dirname, '../src/components'),
  28. 'common': path.resolve(__dirname, '../src/components/Common'),
  29. 'modules': path.resolve(__dirname, '../src/components/Modules'),
  30. 'demo': path.resolve(__dirname, '../src/components/Modules/Demo'),
  31. 'function': path.resolve(__dirname, '../src/components/Modules/Function'),
  32. 'config': path.resolve(__dirname, '../src/config'),
  33. 'store': path.resolve(__dirname, '../src/store'),
  34. 'libs': path.resolve(__dirname, '../src/libs'),
  35. 'util': path.resolve(__dirname, '../src/util'),
  36. 'register': path.resolve(__dirname, '../src/register'),
  37. 'plugins': path.resolve(__dirname, '../src/plugins'),
  38. 'mixin': path.resolve(__dirname, '../src/mixin'),
  39. }
  40. },
  41. resolveLoader: {
  42. fallback: [path.join(__dirname, '../node_modules')]
  43. },
  44. module: {
  45. loaders: [{
  46. test: /\.vue$/,
  47. loader: 'vue'
  48. }, {
  49. test: /\.js$/,
  50. loader: 'babel',
  51. include: [
  52. path.join(projectRoot, 'src')
  53. ],
  54. exclude: /node_modules/
  55. }, {
  56. test: /\.json$/,
  57. loader: 'json'
  58. }, {
  59. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  60. loader: 'url',
  61. query: {
  62. limit: 10000,
  63. name: utils.assetsPath('img/[name].[hash:7].[ext]')
  64. }
  65. }, {
  66. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  67. loader: 'url',
  68. query: {
  69. limit: 10000,
  70. name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
  71. }
  72. }]
  73. },
  74. vue: {
  75. loaders: utils.cssLoaders({
  76. sourceMap: useCssSourceMap
  77. }),
  78. postcss: [
  79. require('autoprefixer')({
  80. browsers: ['last 2 versions']
  81. })
  82. ]
  83. }
  84. }