Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

152 строки
3.4 KiB

  1. var path = require('path')
  2. var webpack = require('webpack')
  3. var ExtractTextPlugin = require('extract-text-webpack-plugin')
  4. var HtmlWebpackPlugin = require('html-webpack-plugin')
  5. const CopyWebpackPlugin = require('copy-webpack-plugin')
  6. var deepExtend = require('deep-extend')
  7. const {gitDescribeSync} = require('git-describe')
  8. var pkg = require('./package.json')
  9. let gitInfo
  10. try {
  11. gitInfo = gitDescribeSync(__dirname)
  12. } catch(e) {
  13. gitInfo = {
  14. hash: 'noGit',
  15. dirty: false
  16. }
  17. }
  18. var commonRules = [
  19. { test: /\.(js(x)?)(\?.*)?$/,
  20. use: [{
  21. loader: 'babel-loader',
  22. options: {
  23. retainLines: true
  24. }
  25. }],
  26. include: [ path.join(__dirname, 'src') ]
  27. },
  28. { test: /\.(txt|yaml)(\?.*)?$/,
  29. loader: 'raw-loader' },
  30. { test: /\.(png|jpg|jpeg|gif|svg)(\?.*)?$/,
  31. loader: 'url-loader?limit=10000' },
  32. { test: /\.(woff|woff2)(\?.*)?$/,
  33. loader: 'url-loader?limit=100000' },
  34. { test: /\.(ttf|eot)(\?.*)?$/,
  35. loader: 'file-loader' }
  36. ]
  37. module.exports = function(rules, options) {
  38. // Special options, that have logic in this file
  39. // ...with defaults
  40. var specialOptions = deepExtend({}, {
  41. hot: false,
  42. separateStylesheets: true,
  43. minimize: false,
  44. longTermCaching: false,
  45. sourcemaps: false,
  46. }, options._special)
  47. var plugins = []
  48. if( specialOptions.separateStylesheets ) {
  49. plugins.push(new ExtractTextPlugin({
  50. filename: '[name].css' + (specialOptions.longTermCaching ? '?[contenthash]' : ''),
  51. allChunks: true
  52. }))
  53. }
  54. if( specialOptions.minimize ) { // production mode
  55. plugins.push(
  56. new webpack.optimize.UglifyJsPlugin({
  57. sourceMap: true,
  58. }),
  59. new webpack.LoaderOptionsPlugin({
  60. options: {
  61. context: __dirname
  62. }
  63. })
  64. )
  65. plugins.push( new webpack.NoEmitOnErrorsPlugin())
  66. } else { // development mode
  67. plugins.push(
  68. new HtmlWebpackPlugin({
  69. template: 'dev-helpers/template.ejs',
  70. })
  71. )
  72. plugins.push(new CopyWebpackPlugin([ { from: 'test/e2e/specs', to: 'test-specs' } ]))
  73. }
  74. plugins.push(
  75. new webpack.DefinePlugin({
  76. 'process.env': {
  77. NODE_ENV: specialOptions.minimize ? JSON.stringify('production') : null,
  78. WEBPACK_INLINE_STYLES: !Boolean(specialOptions.separateStylesheets)
  79. },
  80. 'buildInfo': JSON.stringify({
  81. PACKAGE_VERSION: (pkg.version),
  82. GIT_COMMIT: gitInfo.hash,
  83. GIT_DIRTY: gitInfo.dirty
  84. })
  85. }))
  86. delete options._special
  87. var completeConfig = deepExtend({
  88. entry: {},
  89. output: {
  90. path: path.join(__dirname, 'dist'),
  91. publicPath: '/',
  92. filename: '[name].js',
  93. chunkFilename: '[name].js'
  94. },
  95. target: 'web',
  96. // yaml-js has a reference to `fs`, this is a workaround
  97. node: {
  98. fs: 'empty'
  99. },
  100. module: {
  101. rules: commonRules.concat(rules),
  102. },
  103. resolveLoader: {
  104. modules: [path.join(__dirname, 'node_modules')],
  105. },
  106. externals: {
  107. 'buffertools': true // json-react-schema/deeper depends on buffertools, which fails.
  108. },
  109. resolve: {
  110. modules: [
  111. path.join(__dirname, './src'),
  112. 'node_modules'
  113. ],
  114. extensions: [".web.js", ".js", ".jsx", ".json", ".less"],
  115. alias: {
  116. base: "getbase/src/less/base",
  117. }
  118. },
  119. devtool: specialOptions.sourcemaps ? 'cheap-module-source-map' : null,
  120. plugins,
  121. }, options)
  122. return completeConfig
  123. }