Files
swagger-ui/make-webpack-config.js
RVKen a3249f0d6f Merge branch 'master' into issue-1334
* master: (50 commits)
  update NoErrorsPlugin to NoEmitOnErrorsPlugin
  Undo change to `swagger-client` dependency
  trigger setScheme when a new set of schemes come in
  fix eslint issues
  pin yams version
  update dist
  revert dependencies
  minify bundle css
  migrate webpack to v2.6.1
  #3110 - Fix models down arrow icon in firefox
  Fixes #3299 - export validateNumber and validateInteger for easy reuse and testing. Broke validateParam required check onto multiple lines. Added tests for validateNumber, validateInteger, and validateParam
  Improve README with more information about `urls`
  Rename variable: "selectedName" -> "primaryName"
  "name" -> "urls.primaryName"
  Update selectedIndex when a new URL is loaded
  Use select value to avoid react warning
  Properly added name config Now access it through getConfigs Documented it in README
  Add displayRequestDuration configuration option.
  Fix for #2947 - Display property names for non-object models
  #3256 - Remove unnecessary JSON.stringify call on example values that are already strings
  ...

# Conflicts:
#	dist/swagger-ui-bundle.js
#	dist/swagger-ui-bundle.js.map
#	dist/swagger-ui-standalone-preset.js
#	dist/swagger-ui-standalone-preset.js.map
#	dist/swagger-ui.css
#	dist/swagger-ui.css.map
#	dist/swagger-ui.js
#	dist/swagger-ui.js.map
#	make-webpack-config.js
#	package.json
#	webpack-dist.config.js
#	webpack-hot-dev-server.config.js
2017-06-30 23:24:43 +02:00

156 lines
3.4 KiB
JavaScript

var path = require('path')
var webpack = require('webpack')
var ExtractTextPlugin = require('extract-text-webpack-plugin')
var HtmlWebpackPlugin = require('html-webpack-plugin')
var deepExtend = require('deep-extend')
const {gitDescribeSync} = require('git-describe')
var pkg = require('./package.json')
let gitInfo
try {
gitInfo = gitDescribeSync(__dirname)
} catch(e) {
gitInfo = {
hash: 'noGit',
dirty: false
}
}
var commonRules = [
{ test: /\.(js(x)?)(\?.*)?$/,
use: [{
loader: 'babel-loader',
options: {
retainLines: true
}
}],
include: [ path.join(__dirname, 'src') ]
},
{ test: /\.(txt|yaml)(\?.*)?$/,
loader: 'raw-loader' },
{ test: /\.(png|jpg|jpeg|gif|svg)(\?.*)?$/,
loader: 'url-loader?limit=10000' },
{ test: /\.(woff|woff2)(\?.*)?$/,
loader: 'url-loader?limit=100000' },
{ test: /\.(ttf|eot)(\?.*)?$/,
loader: 'file-loader' }
]
module.exports = function(rules, options) {
// Special options, that have logic in this file
// ...with defaults
var specialOptions = deepExtend({}, {
hot: false,
separateStylesheets: true,
minimize: false,
longTermCaching: false,
sourcemaps: false,
}, options._special)
var plugins = []
if( specialOptions.separateStylesheets ) {
plugins.push(new ExtractTextPlugin({
filename: '[name].css' + (specialOptions.longTermCaching ? '?[contenthash]' : ''),
allChunks: true
}))
}
if( specialOptions.minimize ) { // production mode
plugins.push(
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
}),
new webpack.LoaderOptionsPlugin({
options: {
context: __dirname
}
})
)
plugins.push( new webpack.NoEmitOnErrorsPlugin())
} else { // development mode
var spec
if (specialOptions.testSpecName) {
spec = require('./test/e2e/specs/' + specialOptions.testSpecName)
}
plugins.push(
new HtmlWebpackPlugin({
template: 'dev-helpers/template.ejs',
spec: spec && encodeURI(JSON.stringify(spec)) // using given test spec definition
})
)
}
plugins.push(
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: specialOptions.minimize ? JSON.stringify('production') : null,
WEBPACK_INLINE_STYLES: !Boolean(specialOptions.separateStylesheets)
},
'buildInfo': JSON.stringify({
PACKAGE_VERSION: (pkg.version),
GIT_COMMIT: gitInfo.hash,
GIT_DIRTY: gitInfo.dirty
})
}))
delete options._special
var completeConfig = deepExtend({
entry: {},
output: {
path: path.join(__dirname, 'dist'),
publicPath: '/',
filename: '[name].js',
chunkFilename: '[name].js'
},
target: 'web',
// yaml-js has a reference to `fs`, this is a workaround
node: {
fs: 'empty'
},
module: {
rules: commonRules.concat(rules),
},
resolveLoader: {
modules: [path.join(__dirname, 'node_modules')],
},
externals: {
'buffertools': true // json-react-schema/deeper depends on buffertools, which fails.
},
resolve: {
modules: [
path.join(__dirname, './src'),
'node_modules'
],
extensions: [".web.js", ".js", ".jsx", ".json", ".less"],
alias: {
base: "getbase/src/less/base",
}
},
devtool: specialOptions.sourcemaps ? 'cheap-module-source-map' : null,
plugins,
}, options)
return completeConfig
}