Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 

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