webpack.config.custom.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. var webpack = require('webpack');
  2. var path = require('path');
  3. var config = require('./custom.json');
  4. var ExtractTextPlugin = require('extract-text-webpack-plugin');
  5. var CopyWebpackPlugin = require('copy-webpack-plugin');
  6. var autoprefixer = require('autoprefixer');
  7. var webpackConfig = module.exports = {};
  8. webpackConfig.entry = {
  9. nutui: './src/nutui-custom.js'
  10. };
  11. webpackConfig.output = {
  12. path: path.resolve(__dirname, 'dist'),
  13. publicPath: "/",
  14. filename: 'nutui.js',
  15. library: 'nutui',
  16. libraryTarget: 'umd',
  17. umdNamedDefine: true
  18. };
  19. webpackConfig.module = {
  20. rules: [{
  21. test: /\.css$/,
  22. use: ['style-loader', 'css-loader', 'postcss-loader']
  23. }, {
  24. test: /\.scss$/,
  25. use: ['style-loader', 'css-loader', 'sass-loader', 'postcss-loader']
  26. }, {
  27. test: /\.vue$/,
  28. loader: 'vue-loader',
  29. options: {
  30. postcss: [autoprefixer()]
  31. }
  32. }, {
  33. test: /\.svg$/,
  34. loader: 'svg-sprite-loader'
  35. }, {
  36. test: /\.js$/,
  37. loader: 'babel-loader',
  38. exclude: /node_modules/,
  39. }, {
  40. test: /\.(png|jpg|gif|webp)$/,
  41. loader: 'url-loader',
  42. options: {
  43. limit: 3000,
  44. name: 'img/[name].[ext]',
  45. }
  46. }, ]
  47. };
  48. webpackConfig.externals = {
  49. 'vue': {
  50. root: 'Vue',
  51. commonjs: 'vue',
  52. commonjs2: 'vue',
  53. amd: 'vue'
  54. }
  55. };
  56. webpackConfig.plugins = [
  57. new webpack.LoaderOptionsPlugin({
  58. minimize: false
  59. }),
  60. new webpack.optimize.UglifyJsPlugin({
  61. ecma: 6,
  62. compress: {
  63. warnings: false
  64. }
  65. }),
  66. new webpack.BannerPlugin('NutUI v' + config.version + ' ' + new Date().toString())
  67. ];
  68. webpackConfig.devtool = '#cheap-module-source-map';
  69. webpackConfig.plugins = (webpackConfig.plugins || []).concat([
  70. new webpack.DefinePlugin({
  71. 'process.env': {
  72. NODE_ENV: '"production"'
  73. },
  74. 'CONFIG': config
  75. }),
  76. new webpack.LoaderOptionsPlugin({
  77. minimize: false
  78. })
  79. ]);