base.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. const path = require('path')
  2. const { VueLoaderPlugin } = require('vue-loader')
  3. const HtmlWebpackPlugin = require('html-webpack-plugin')
  4. const webpack = require('webpack')
  5. module.exports = {
  6. output: {
  7. filename: 'js/[name].js',
  8. path: path.join(process.cwd(), '/dist/'),
  9. clean: true
  10. },
  11. resolve: {
  12. alias: {
  13. '@jg_widgets': path.resolve(__dirname, '../node_modules/jg_widgets/packages'),
  14. vue: "vue/dist/vue.esm.js",
  15. },
  16. extensions: ['.tsx', '.ts', '.js', '.vue', '.css', '.scss']
  17. },
  18. module: {
  19. rules: [
  20. {
  21. test: /\.vue$/,
  22. use: 'vue-loader',
  23. exclude: /node_modules/
  24. }, {
  25. test: /\.s[ac]ss$/,
  26. use: ['style-loader', 'css-loader', 'sass-loader'],
  27. exclude: /node_modules/
  28. }, {
  29. test: /\.css$/,
  30. use: ['style-loader', 'css-loader', {
  31. loader: 'postcss-loader',
  32. options: {
  33. postcssOptions: {
  34. plugins: [['postcss-preset-env', { browsers: '>0.01%' }]]
  35. }
  36. }
  37. }]
  38. },
  39. {
  40. test: /\.html$/i,
  41. loader: "html-loader",
  42. },
  43. {
  44. test: /\.(jpe?g|png|gif|svg)$/,
  45. exclude: /node_modules/,
  46. type: 'javascript/auto', // ! type 与 esModule处理css中url图片被生成两次,并且css导入的那次图片资源无效的问题
  47. use: [
  48. {
  49. loader: 'url-loader',
  50. options: {
  51. esModule: false,
  52. publicPath: './',
  53. limit: 2048,
  54. name: `image/[name].[hash].[ext]`
  55. }
  56. }
  57. ]
  58. },
  59. {
  60. test: /\.m?js$/,
  61. resolve: {
  62. fullySpecified: false
  63. }
  64. },
  65. {
  66. test: /\.(js|ts)$/,
  67. exclude: /node_modules/,
  68. use: [
  69. {
  70. loader: 'babel-loader',
  71. options: {
  72. presets: [
  73. [
  74. '@babel/preset-env',
  75. {
  76. modules: false, // ! 避免转换commonjs影响tree shaking
  77. corejs: '3', // ! 自动按需注入垫片
  78. targets: '>0.25%',
  79. useBuiltIns: 'usage'
  80. }
  81. ],
  82. [
  83. '@babel/preset-typescript',
  84. {
  85. allExtensions: true // ! .vue文件需要
  86. }
  87. ]
  88. ],
  89. plugins: []
  90. }
  91. }
  92. ]
  93. }
  94. ]
  95. },
  96. plugins: [
  97. new VueLoaderPlugin(),
  98. new webpack.ProvidePlugin({
  99. process: 'process/browser'
  100. }),
  101. new HtmlWebpackPlugin({
  102. title: 'app',
  103. template: path.resolve(__dirname, './template.ejs')
  104. })
  105. ]
  106. }
  107. // 阻止ts全局类型推导报错
  108. export { }