webpack.base.conf.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. var webpack = require("webpack");
  2. ("use strict");
  3. const path = require("path");
  4. const utils = require("./utils");
  5. const config = require("../config");
  6. const vueLoaderConfig = require("./vue-loader.conf");
  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. app: ["babel-polyfill", "./src/main.js"]
  25. },
  26. output: {
  27. path: config.build.assetsRoot,
  28. filename: "[name].js",
  29. publicPath:
  30. process.env.NODE_ENV === "production"
  31. ? config.build.assetsPublicPath
  32. : config.dev.assetsPublicPath,
  33. },
  34. resolve: {
  35. extensions: [".js", ".vue", ".json"],
  36. alias: {
  37. vue$: "vue/dist/vue.esm.js",
  38. "@": resolve("src"),
  39. },
  40. },
  41. module: {
  42. rules: [
  43. ...(config.dev.useEslint ? [createLintingRule()] : []),
  44. {
  45. test: /\.vue$/,
  46. loader: "vue-loader",
  47. options: vueLoaderConfig,
  48. },
  49. {
  50. test: /\.js$/,
  51. loader: "babel-loader",
  52. include: [
  53. resolve("src"),
  54. resolve("test"),
  55. resolve("node_modules/webpack-dev-server/client"),
  56. ],
  57. },
  58. {
  59. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  60. loader: "url-loader",
  61. options: {
  62. limit: 10000,
  63. name: utils.assetsPath("img/[name].[hash:7].[ext]"),
  64. },
  65. },
  66. {
  67. test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
  68. loader: "url-loader",
  69. options: {
  70. limit: 10000,
  71. name: utils.assetsPath("media/[name].[hash:7].[ext]"),
  72. },
  73. },
  74. {
  75. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  76. loader: "url-loader",
  77. options: {
  78. limit: 10000,
  79. name: utils.assetsPath("fonts/[name].[hash:7].[ext]"),
  80. },
  81. },
  82. {
  83. test: /\.scss$/,
  84. use: ["style-loader", "css-loader", "sass-loader"],
  85. },
  86. {
  87. test: /\.less$/,
  88. loader: "style-loader!css-loader!less-loader",
  89. },
  90. ],
  91. },
  92. node: {
  93. // prevent webpack from injecting useless setImmediate polyfill because Vue
  94. // source contains it (although only uses it if it's native).
  95. setImmediate: false,
  96. // prevent webpack from injecting mocks to Node native modules
  97. // that does not make sense for the client
  98. dgram: "empty",
  99. fs: "empty",
  100. net: "empty",
  101. tls: "empty",
  102. child_process: "empty",
  103. },
  104. };