webpack.config.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. const webpack = require('webpack')
  2. const path = require('path')
  3. const HtmlWebpackPlugin = require('html-webpack-plugin')
  4. const CopyWebpackPlugin = require('copy-webpack-plugin');
  5. const config =
  6. {
  7. entry: path.join(__dirname, 'src/CAD/index.ts'),
  8. output: {
  9. path: path.join(__dirname, 'dist'),
  10. filename: 'bundle.js',
  11. globalObject: 'this'
  12. },
  13. module: {
  14. rules: [
  15. {
  16. test: /\.worker\.js$/, //以.worker.js结尾的文件将被worker-loader加载
  17. use: { loader: 'worker-loader' }
  18. },
  19. // {
  20. // test: /\.js$/,
  21. // exclude: /node_modules/,
  22. // use: {
  23. // loader: 'babel-loader'
  24. // }
  25. // },
  26. {
  27. test: /\.tsx?$/,
  28. use: 'ts-loader',
  29. exclude: /node_modules/
  30. },
  31. {
  32. test: /\.css$/,
  33. use: [
  34. {loader: 'style-loader'},
  35. {loader: 'css-loader'},
  36. {
  37. loader: 'postcss-loader',
  38. options: {
  39. plugins: [require('autoprefixer')]
  40. }
  41. }
  42. ]
  43. },
  44. {
  45. test: /\.(png|jpg|gif|woff|eot|ttf|svg)$/,
  46. use: {
  47. loader: 'url-loader',
  48. options: {
  49. limit: 8192,
  50. name: "assets/[name].[ext]"
  51. }
  52. }
  53. }
  54. ]
  55. },
  56. resolve: {
  57. extensions: ['.tsx', '.ts', '.js']
  58. },
  59. plugins: [
  60. new webpack.HotModuleReplacementPlugin(),
  61. new CopyWebpackPlugin([{
  62. from: path.resolve(__dirname, 'static'),
  63. to: path.resolve(__dirname, 'dist', 'static'),
  64. ignore: ['.*']
  65. }]),
  66. new HtmlWebpackPlugin({
  67. template: path.join(__dirname, 'static/index.html'),
  68. minify: {
  69. removeComments: false,
  70. collapseWhitespace: false
  71. }
  72. })
  73. ]
  74. ,
  75. devServer: {
  76. contentBase: path.join(__dirname, "dist"),
  77. port: 8001,
  78. hot: true,
  79. host: '0.0.0.0'
  80. }
  81. }
  82. module.exports = config