webpack.base.conf.js 2.8 KB

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