您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

141 行
3.0 KiB

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