base.config.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import Webpack from 'webpack';
  2. import WebpackBar from 'webpackbar';
  3. import { VueLoaderPlugin } from 'vue-loader';
  4. import { ROOT_CLI_PATH, ROOT_PACKAGE_PATH } from '../util/dic';
  5. import { isDev, isTest } from '../util';
  6. import MiniCssExtractPlugin from 'mini-css-extract-plugin';
  7. const config = require(ROOT_PACKAGE_PATH('package.json'));
  8. export const baseConfig: Webpack.Configuration = {
  9. stats: 'errors-only',
  10. output: {
  11. publicPath: './' //相对路径
  12. },
  13. resolve: {
  14. extensions: ['.js', '.vue', '.json'],
  15. alias: {
  16. vue$: 'vue/dist/vue.esm.js',
  17. '@': ROOT_PACKAGE_PATH('src')
  18. },
  19. symlinks: false
  20. },
  21. module: {
  22. rules: [
  23. isTest()
  24. ? {}
  25. : {
  26. test: /\.(sa|sc|c)ss$/,
  27. use: [
  28. isDev() ? 'style-loader' : MiniCssExtractPlugin.loader,
  29. 'css-loader',
  30. 'postcss-loader',
  31. {
  32. loader: 'sass-loader',
  33. options: {
  34. prependData: `@import "@/styles/index.scss"; `
  35. }
  36. }
  37. ]
  38. },
  39. {
  40. test: /\.vue$/,
  41. use: [
  42. 'cache-loader',
  43. {
  44. loader: 'vue-loader',
  45. options: {
  46. loaders: {
  47. sass: ['style-loader', 'css-loader', 'sass-loader', 'postcss-loader']
  48. }
  49. }
  50. }
  51. ]
  52. },
  53. {
  54. test: /\.js$/,
  55. include: [ROOT_PACKAGE_PATH('src'), ROOT_CLI_PATH('site')],
  56. use: ['cache-loader', 'babel-loader']
  57. },
  58. {
  59. test: /\.(png|jpe?g|gif|webp)$/,
  60. loader: 'url-loader',
  61. include: [ROOT_PACKAGE_PATH('src/assets/img'), ROOT_CLI_PATH('site')],
  62. options: {
  63. limit: 3000,
  64. name: 'img/[name].[ext]',
  65. esModule: false // 否则加载时为 [object]
  66. }
  67. },
  68. {
  69. test: /\.svg$/,
  70. loader: 'raw-loader',
  71. include: [ROOT_PACKAGE_PATH('src/assets/svg')],
  72. options: {
  73. esModule: false // 否则加载时为 [object]
  74. }
  75. }
  76. ]
  77. },
  78. plugins: [
  79. new Webpack.BannerPlugin({
  80. banner: `NutUI v${config.version} - [filebase], [hash], ${new Date()}
  81. (c) 2017-2020 JDC
  82. Released under the MIT License.`
  83. }),
  84. new VueLoaderPlugin(),
  85. new WebpackBar({
  86. name: 'NutUI CLI',
  87. color: '#5396ff'
  88. })
  89. ]
  90. };