webpack.start.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /**
  2. * @fileoverview demo.
  3. *
  4. * @author <a href="http://vanessa.b3log.org">Liyuan Li</a>
  5. * @version 0.3.0.0, Sep 3, 2019
  6. */
  7. const path = require('path')
  8. const webpack = require('webpack')
  9. const HtmlWebpackPlugin = require('html-webpack-plugin')
  10. const CopyPlugin = require('copy-webpack-plugin')
  11. const pkg = require('./package.json')
  12. module.exports = {
  13. mode: 'development',
  14. output: {
  15. filename: '[name]',
  16. path: path.resolve(__dirname, 'demo/dist'),
  17. },
  18. entry: {
  19. 'index.js': './demo/index.js',
  20. 'render.js': './demo/render.js',
  21. 'jest-puppeteer.js': './demo/jest-puppeteer.js',
  22. 'comment.js': './demo/comment.js',
  23. },
  24. resolve: {
  25. extensions: ['.js', '.ts', '.png', '.less'],
  26. },
  27. module: {
  28. rules: [
  29. {
  30. test: /\.less$/,
  31. include: [path.resolve(__dirname, 'src')],
  32. use: [
  33. {
  34. loader: 'style-loader',
  35. },
  36. {
  37. loader: 'css-loader', // translates CSS into CommonJS
  38. options: {
  39. url: false,
  40. },
  41. },
  42. {
  43. loader: 'postcss-loader',
  44. options: {
  45. postcssOptions: {
  46. plugins: [
  47. ['autoprefixer', {grid: true, remove: false}],
  48. ],
  49. },
  50. },
  51. },
  52. {
  53. loader: 'less-loader', // compiles Less to CSS
  54. },
  55. ],
  56. },
  57. {
  58. test: /\.ts$/,
  59. use: 'ts-loader',
  60. },
  61. {
  62. test: /\.js$/,
  63. exclude: '/node_modules/',
  64. use: {
  65. loader: 'babel-loader',
  66. options: {
  67. presets: [
  68. [
  69. '@babel/env',
  70. {
  71. targets: {
  72. browsers: [
  73. 'last 2 Chrome major versions',
  74. 'last 2 Firefox major versions',
  75. 'last 2 Safari major versions',
  76. 'last 2 Edge major versions',
  77. 'last 2 iOS major versions',
  78. 'last 2 ChromeAndroid major versions',
  79. ],
  80. },
  81. },
  82. ],
  83. ],
  84. },
  85. },
  86. },
  87. {
  88. test: /\.png$/,
  89. include: [path.resolve(__dirname, './src/assets/images')],
  90. use: [
  91. 'file-loader',
  92. ],
  93. },
  94. ],
  95. },
  96. plugins: [
  97. new HtmlWebpackPlugin({
  98. chunks: ['index.js'],
  99. filename: './index.html',
  100. template: './demo/index.html',
  101. }),
  102. new HtmlWebpackPlugin({
  103. chunks: ['render.js'],
  104. filename: './render.html',
  105. template: './demo/render.html',
  106. }),
  107. new HtmlWebpackPlugin({
  108. chunks: ['jest-puppeteer.js'],
  109. filename: './jest-puppeteer.html',
  110. template: './demo/jest-puppeteer.html',
  111. }),
  112. new HtmlWebpackPlugin({
  113. chunks: ['comment.js'],
  114. filename: './comment.html',
  115. template: './demo/comment.html',
  116. }),
  117. new webpack.DefinePlugin({
  118. VDITOR_VERSION: JSON.stringify(pkg.version),
  119. }),
  120. new CopyPlugin({
  121. patterns: [
  122. {from: 'src/css', to: 'css'},
  123. {from: 'src/images', to: 'images'},
  124. {from: 'src/js', to: 'js'},
  125. {from: 'types', to: 'types'},
  126. ],
  127. }),
  128. ],
  129. devServer: {
  130. static: {
  131. directory: path.join(__dirname, '.'),
  132. },
  133. port: 9000,
  134. host: '0.0.0.0',
  135. proxy: {
  136. '/api': {
  137. target: 'http://localhost:8080',
  138. pathRewrite: {'^/api': ''},
  139. },
  140. '/ld246': {
  141. target: 'https://ld246.com',
  142. pathRewrite: {'^/ld246': ''},
  143. },
  144. },
  145. },
  146. }