You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

webpack.plugins.conf.js 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * @Author: Caven
  3. * @Date: 2020-01-18 18:22:23
  4. * @Last Modified by: Caven
  5. * @Last Modified time: 2020-01-21 10:41:59
  6. */
  7. const path = require('path')
  8. const webpack = require('webpack')
  9. const MiniCssExtractPlugin = require('mini-css-extract-plugin')
  10. const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
  11. function resolve(dir) {
  12. return path.join(__dirname, '.', dir)
  13. }
  14. module.exports = env => {
  15. const IS_PROD = (env && env.production) || false
  16. const publicPath = IS_PROD ? '/' : '/'
  17. let plugins = [
  18. new MiniCssExtractPlugin({
  19. filename: IS_PROD ? '[name].min.css' : '[name].css',
  20. allChunks: true
  21. })
  22. ]
  23. if (IS_PROD) {
  24. plugins.push(new OptimizeCssAssetsPlugin())
  25. plugins.push(new webpack.NoEmitOnErrorsPlugin())
  26. }
  27. return {
  28. entry: {
  29. 'dc.plugins': ['entry']
  30. },
  31. devtool: IS_PROD ? false : 'cheap-module-eval-source-map',
  32. output: {
  33. filename: IS_PROD ? '[name].min.js' : '[name].js',
  34. path: path.resolve(__dirname, 'dist/dc-sdk/plugins'),
  35. publicPath: publicPath,
  36. sourcePrefix: ''
  37. },
  38. amd: {
  39. toUrlUndefinded: true
  40. },
  41. node: {
  42. fs: 'empty'
  43. },
  44. module: {
  45. unknownContextCritical: false,
  46. rules: [
  47. {
  48. test: /\.js$/,
  49. enforce: 'pre',
  50. use: [
  51. {
  52. loader: 'strip-pragma-loader',
  53. options: {
  54. pragmas: {
  55. debug: false
  56. }
  57. }
  58. }
  59. ]
  60. },
  61. {
  62. test: /\.js$/,
  63. exclude: /node_modules/,
  64. loader: 'babel-loader',
  65. query: {
  66. presets: ['@babel/preset-env'],
  67. compact: false,
  68. ignore: ['checkTree']
  69. }
  70. },
  71. {
  72. test: /\.css$/,
  73. use: [
  74. MiniCssExtractPlugin.loader,
  75. {
  76. loader: 'css-loader'
  77. },
  78. {
  79. loader: 'sass-loader'
  80. }
  81. ]
  82. },
  83. {
  84. test: /\.scss$/,
  85. use: [
  86. MiniCssExtractPlugin.loader,
  87. {
  88. loader: 'css-loader'
  89. },
  90. {
  91. loader: 'sass-loader'
  92. }
  93. ]
  94. },
  95. {
  96. test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
  97. loader: 'url-loader',
  98. options: {
  99. limit: 20000
  100. }
  101. }
  102. ]
  103. },
  104. resolve: {
  105. extensions: ['.js', '.json', '.css'],
  106. alias: {
  107. '@': resolve('src'),
  108. entry: './src/plugins/DC.Pulgins.js'
  109. }
  110. },
  111. plugins
  112. }
  113. }