webpack.dev.conf.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. const config = require('../package.json');
  2. const path = require('path');
  3. const webpackBaseConf = require('./webpack.base.conf.js');
  4. const HtmlWebpackPlugin = require('html-webpack-plugin');
  5. const MiniCssExtractPlugin = require("mini-css-extract-plugin");
  6. const merge = require('webpack-merge');
  7. const mdtohtml = require('../scripts/mdToVue');
  8. const isDev = process.env.NODE_ENV === 'development';
  9. module.exports = merge(webpackBaseConf, {
  10. mode: 'development',
  11. entry: {
  12. 'nutui-mobile': './sites/demo/app.js',
  13. 'nutui-doc': './sites/doc/app.js',
  14. },
  15. output: {
  16. publicPath: '/',
  17. filename: '[name].js',
  18. },
  19. module: {
  20. rules: [
  21. //自定义主题
  22. // {
  23. // test: /\.(sa|sc|c)ss$/,
  24. // use: [
  25. // {
  26. // loader: 'sass-loader',
  27. // options: {
  28. // data: `@import "./sites/demo/asset/css/custom.scss";@import "./src/styles/index.scss"; `,
  29. // },
  30. // }
  31. // ],
  32. // }
  33. ]
  34. },
  35. optimization: {
  36. splitChunks: {
  37. cacheGroups: {
  38. chunks: {
  39. chunks: 'all',
  40. minChunks: 2,
  41. minSize: 0,
  42. name: 'chunks'
  43. }
  44. }
  45. }
  46. },
  47. plugins: [
  48. //demo
  49. new HtmlWebpackPlugin({
  50. template: './sites/demo/index.html',
  51. filename: 'demo.html',
  52. hash: true,//防止缓存
  53. inject: true,
  54. chunks: ['chunks', 'nutui-mobile'],
  55. minify: {
  56. multihtmlCache: true,// 解决多页打包的关键!
  57. minifyJS: true,
  58. minifyCSS: true,
  59. removeAttributeQuotes: true//压缩 去掉引号
  60. }
  61. }),
  62. // doc
  63. new mdtohtml({
  64. entry: './src',
  65. output: './sites/doc/view/',
  66. template: './doc-site/template.html',
  67. nav: 'left',
  68. needCode: true,
  69. isbuild: isDev,
  70. hasMarkList: false
  71. }),
  72. new mdtohtml({
  73. entry: './docs',
  74. output: './sites/doc/page/',
  75. template: './doc-site/template.html',
  76. nav: 'left',
  77. needCode: false,
  78. isbuild: isDev
  79. }),
  80. new HtmlWebpackPlugin({
  81. template: './sites/doc/index.html',
  82. filename: 'default.html',
  83. hash: true,//防止缓存
  84. inject: true,
  85. chunks: ['chunks', 'nutui-doc'],
  86. minify: {
  87. multihtmlCache: true,// 解决多页打包的关键!
  88. minifyJS: true,
  89. minifyCSS: true,
  90. removeAttributeQuotes: true//压缩 去掉引号
  91. }
  92. }),
  93. ],
  94. devtool: 'cheap-module-eval-source-map',
  95. devServer: {
  96. contentBase: path.resolve(__dirname, 'dist/sites'),
  97. compress: true,
  98. index: 'default.html',
  99. historyApiFallback: true,
  100. disableHostCheck: true,
  101. host: "0.0.0.0",
  102. hot: true,
  103. hotOnly: true,
  104. inline: true,
  105. overlay: {
  106. warnings: true,
  107. errors: true
  108. },
  109. watchOptions: {
  110. ignored: /node_modules/
  111. }
  112. }
  113. });