webpack.base.conf.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. "use strict";
  2. const path = require("path");
  3. const utils = require("./utils");
  4. const config = require("../config");
  5. const vueLoaderConfig = require("./vue-loader.conf");
  6. const webpack = require("webpack");
  7. function resolve(dir) {
  8. return path.join(__dirname, "..", dir);
  9. }
  10. // const createLintingRule = () => ({
  11. // test: /\.(js|vue)$/,
  12. // loader: 'eslint-loader',
  13. // enforce: 'pre',
  14. // include: [resolve('src'), resolve('test')],
  15. // options: {
  16. // formatter: require('eslint-friendly-formatter'),
  17. // emitWarning: !config.dev.showEslintErrorsInOverlay
  18. // }
  19. // })
  20. module.exports = {
  21. context: path.resolve(__dirname, "../"),
  22. entry: {
  23. app: "./src/main.js"
  24. },
  25. externals: {
  26. BMap: "BMap"
  27. },
  28. output: {
  29. path: config.build.assetsRoot,
  30. filename: "[name].js",
  31. publicPath:
  32. process.env.NODE_ENV === "production"
  33. ? config.build.assetsPublicPath
  34. : config.dev.assetsPublicPath
  35. },
  36. resolve: {
  37. extensions: [".js", ".vue", ".json"],
  38. alias: {
  39. vue$: "vue/dist/vue.esm.js",
  40. "@": resolve("src")
  41. }
  42. },
  43. module: {
  44. rules: [
  45. ...(config.dev.useEslint ? [] : []),
  46. {
  47. test: /\.vue$/,
  48. loader: "vue-loader",
  49. options: vueLoaderConfig
  50. },
  51. {
  52. test: /\.js$/,
  53. loader: "babel-loader?cacheDirectory",
  54. include: [
  55. resolve("src"),
  56. resolve("test"),
  57. resolve("node_modules/webpack-dev-server/client")
  58. ]
  59. },
  60. {
  61. test: /\.svg$/,
  62. loader: "svg-sprite-loader",
  63. include: [resolve("src/icons")],
  64. options: {
  65. symbolId: "icon-[name]"
  66. }
  67. },
  68. {
  69. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  70. loader: "url-loader",
  71. exclude: [resolve("src/icons")],
  72. options: {
  73. limit: 10000,
  74. name: utils.assetsPath("img/[name].[hash:7].[ext]")
  75. }
  76. },
  77. {
  78. test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
  79. loader: "url-loader",
  80. options: {
  81. limit: 10000,
  82. name: utils.assetsPath("media/[name].[hash:7].[ext]")
  83. }
  84. },
  85. {
  86. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  87. loader: "url-loader",
  88. options: {
  89. limit: 10000,
  90. name: utils.assetsPath("fonts/[name].[hash:7].[ext]")
  91. }
  92. },
  93. {
  94. test: /\.sass$/,
  95. loaders: ["style", "css", "sass"]
  96. }
  97. ]
  98. },
  99. node: {
  100. // prevent webpack from injecting useless setImmediate polyfill because Vue
  101. // source contains it (although only uses it if it's native).
  102. setImmediate: false,
  103. // prevent webpack from injecting mocks to Node native modules
  104. // that does not make sense for the client
  105. dgram: "empty",
  106. fs: "empty",
  107. net: "empty",
  108. tls: "empty",
  109. child_process: "empty"
  110. },
  111. plugins: [
  112. new webpack.ProvidePlugin({
  113. $: "jquery",
  114. jQuery: "jquery"
  115. })
  116. ]
  117. };