No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

152 líneas
3.4 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. longTermCaching: false,
  49. sourcemaps: false,
  50. }, options._special)
  51. var plugins = []
  52. if( specialOptions.separateStylesheets ) {
  53. plugins.push(new ExtractTextPlugin({
  54. filename: "[name].css" + (specialOptions.longTermCaching ? "?[contenthash]" : ""),
  55. allChunks: true
  56. }))
  57. }
  58. if( specialOptions.minimize ) { // production mode
  59. plugins.push(
  60. new UglifyJsPlugin({
  61. sourceMap: true,
  62. }),
  63. new webpack.LoaderOptionsPlugin({
  64. options: {
  65. context: __dirname
  66. }
  67. })
  68. )
  69. plugins.push( new webpack.NoEmitOnErrorsPlugin())
  70. } else { // development mode
  71. plugins.push(new CopyWebpackPlugin([ { from: "test/e2e/specs", to: "test-specs" } ]))
  72. }
  73. plugins.push(
  74. new webpack.DefinePlugin({
  75. "process.env": {
  76. NODE_ENV: specialOptions.minimize ? JSON.stringify("production") : null,
  77. WEBPACK_INLINE_STYLES: !specialOptions.separateStylesheets
  78. },
  79. "buildInfo": JSON.stringify({
  80. PACKAGE_VERSION: (pkg.version),
  81. GIT_COMMIT: gitInfo.hash,
  82. GIT_DIRTY: gitInfo.dirty,
  83. HOSTNAME: os.hostname(),
  84. BUILD_TIME: new Date().toUTCString()
  85. })
  86. }))
  87. delete options._special
  88. var completeConfig = deepExtend({
  89. entry: {},
  90. output: {
  91. path: path.join(__dirname, "dist"),
  92. publicPath: "/",
  93. filename: "[name].js",
  94. chunkFilename: "[name].js"
  95. },
  96. target: "web",
  97. // yaml-js has a reference to `fs`, this is a workaround
  98. node: {
  99. fs: "empty"
  100. },
  101. module: {
  102. rules: commonRules.concat(rules),
  103. },
  104. resolveLoader: {
  105. modules: [path.join(__dirname, "node_modules")],
  106. },
  107. externals: {
  108. "buffertools": true // json-react-schema/deeper depends on buffertools, which fails.
  109. },
  110. resolve: {
  111. modules: [
  112. path.join(__dirname, "./src"),
  113. "node_modules"
  114. ],
  115. extensions: [".web.js", ".js", ".jsx", ".json", ".less"],
  116. alias: {
  117. base: "getbase/src/less/base",
  118. }
  119. },
  120. devtool: specialOptions.sourcemaps ? "nosource-source-map" : false,
  121. plugins,
  122. }, options)
  123. return completeConfig
  124. }