webpack.base.conf.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 weither to enable CSS Sourcemaps 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 != 'development' && config.build.productionSourceMap)
  10. var useCssSourceMap = cssSourceMapDev || cssSourceMapProd
  11. var ExtractPlugin = require('extract-text-webpack-plugin');
  12. module.exports = {
  13. entry: {
  14. app: './src/main.js'
  15. },
  16. output: {
  17. path: config.build.assetsRoot,
  18. publicPath: process.env.NODE_ENV != 'development' ? config.build.assetsPublicPath : config.dev.assetsPublicPath,
  19. filename: '[name].js'
  20. },
  21. resolve: {
  22. extensions: ['', '.js', '.vue'],
  23. fallback: [path.join(__dirname, '../node_modules')],
  24. alias: {
  25. 'vue$': 'vue/dist/vue',
  26. 'src': path.resolve(__dirname, '../src'),
  27. 'assets': path.resolve(__dirname, '../src/assets'),
  28. 'components': path.resolve(__dirname, '../src/components')
  29. }
  30. },
  31. resolveLoader: {
  32. fallback: [path.join(__dirname, '../node_modules')]
  33. },
  34. module: {
  35. // preLoaders: [
  36. // {
  37. // test: /\.vue$/,
  38. // loader: 'eslint',
  39. // include: projectRoot,
  40. // exclude: /node_modules/
  41. // },
  42. // {
  43. // test: /\.js$/,
  44. // loader: 'eslint',
  45. // include: projectRoot,
  46. // exclude: /node_modules/
  47. // }
  48. // ],
  49. loaders: [
  50. {
  51. test: /\.vue$/,
  52. loader: 'vue'
  53. },
  54. {
  55. test: /\.js$/,
  56. loader: 'babel',
  57. include: projectRoot,
  58. exclude: /node_modules/
  59. },
  60. {
  61. test: /\.json$/,
  62. loader: 'json'
  63. },
  64. {
  65. test:/\.scss$/,
  66. loader:ExtractPlugin.extract('style-loader', 'css-loader!sass-loader')
  67. },
  68. {
  69. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  70. loader: 'url',
  71. query: {
  72. limit: 10000,
  73. name: utils.assetsPath('img/[name].[hash:7].[ext]')
  74. }
  75. },
  76. {
  77. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  78. loader: 'url',
  79. query: {
  80. limit: 10000,
  81. name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
  82. }
  83. }
  84. ]
  85. },
  86. eslint: {
  87. formatter: require('eslint-friendly-formatter')
  88. },
  89. vue: {
  90. loaders: utils.cssLoaders({ sourceMap: useCssSourceMap }),
  91. postcss: [
  92. require('autoprefixer')({
  93. browsers: ['last 2 versions']
  94. })
  95. ]
  96. }
  97. }