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

148 строки
3.3 KiB

  1. var path = require("path")
  2. var webpack = require('webpack')
  3. var ExtractTextPlugin = require('extract-text-webpack-plugin')
  4. const CopyWebpackPlugin = require('copy-webpack-plugin')
  5. var deepExtend = require('deep-extend')
  6. const {gitDescribeSync} = require('git-describe')
  7. const os = require("os")
  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(new CopyWebpackPlugin([ { from: 'test/e2e/specs', to: 'test-specs' } ]))
  68. }
  69. plugins.push(
  70. new webpack.DefinePlugin({
  71. "process.env": {
  72. NODE_ENV: specialOptions.minimize ? JSON.stringify("production") : null,
  73. WEBPACK_INLINE_STYLES: !specialOptions.separateStylesheets
  74. },
  75. "buildInfo": JSON.stringify({
  76. PACKAGE_VERSION: (pkg.version),
  77. GIT_COMMIT: gitInfo.hash,
  78. GIT_DIRTY: gitInfo.dirty,
  79. HOSTNAME: os.hostname(),
  80. BUILD_TIME: new Date().toUTCString()
  81. })
  82. }))
  83. delete options._special
  84. var completeConfig = deepExtend({
  85. entry: {},
  86. output: {
  87. path: path.join(__dirname, "dist"),
  88. publicPath: "/",
  89. filename: "[name].js",
  90. chunkFilename: "[name].js"
  91. },
  92. target: "web",
  93. // yaml-js has a reference to `fs`, this is a workaround
  94. node: {
  95. fs: "empty"
  96. },
  97. module: {
  98. rules: commonRules.concat(rules),
  99. },
  100. resolveLoader: {
  101. modules: [path.join(__dirname, "node_modules")],
  102. },
  103. externals: {
  104. "buffertools": true // json-react-schema/deeper depends on buffertools, which fails.
  105. },
  106. resolve: {
  107. modules: [
  108. path.join(__dirname, "./src"),
  109. "node_modules"
  110. ],
  111. extensions: [".web.js", ".js", ".jsx", ".json", ".less"],
  112. alias: {
  113. base: "getbase/src/less/base",
  114. }
  115. },
  116. devtool: specialOptions.sourcemaps ? "nosource-source-map" : null,
  117. plugins,
  118. }, options)
  119. return completeConfig
  120. }