2016-08-28 21:46:10 +03:00
|
|
|
const webpack = require('webpack');
|
|
|
|
const ForkCheckerPlugin = require('awesome-typescript-loader').ForkCheckerPlugin;
|
2016-10-31 12:03:15 +03:00
|
|
|
const StringReplacePlugin = require("string-replace-webpack-plugin");
|
2016-08-28 21:46:10 +03:00
|
|
|
|
|
|
|
const root = require('./helpers').root;
|
|
|
|
const VERSION = JSON.stringify(require('../package.json').version);
|
2016-08-30 19:53:06 +03:00
|
|
|
const IS_PRODUCTION = process.env.NODE_ENV === "production";
|
2016-08-28 21:46:10 +03:00
|
|
|
// TODO Refactor common parts of config
|
|
|
|
|
|
|
|
module.exports = {
|
2016-11-01 10:57:06 +03:00
|
|
|
devtool: '#inline-source-map',
|
2016-08-28 21:46:10 +03:00
|
|
|
|
|
|
|
resolve: {
|
2016-09-27 09:03:04 +03:00
|
|
|
extensions: ['.ts', '.js', '.json', '.css'],
|
2016-08-28 21:46:10 +03:00
|
|
|
alias: {
|
|
|
|
http: 'stream-http',
|
|
|
|
https: 'stream-http'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
externals: {
|
2016-10-18 17:06:00 +03:00
|
|
|
'jquery': 'jquery',
|
2016-09-02 23:24:51 +03:00
|
|
|
'esprima': 'esprima' // optional dep of ys-yaml not needed for redoc
|
2016-08-28 21:46:10 +03:00
|
|
|
},
|
|
|
|
node: {
|
2016-09-02 23:24:51 +03:00
|
|
|
fs: "empty",
|
|
|
|
crypto: "empty",
|
2016-09-27 09:03:04 +03:00
|
|
|
global: true,
|
2016-09-02 23:24:51 +03:00
|
|
|
process: true,
|
|
|
|
module: false,
|
|
|
|
clearImmediate: false,
|
|
|
|
setImmediate: false
|
2016-08-28 21:46:10 +03:00
|
|
|
},
|
|
|
|
entry: {
|
|
|
|
'redoc': './lib/index.ts',
|
|
|
|
'vendor': './lib/vendor.ts',
|
|
|
|
'polyfills': './lib/polyfills.ts'
|
|
|
|
},
|
|
|
|
|
|
|
|
devServer: {
|
2016-11-29 10:20:11 +03:00
|
|
|
contentBase: root('demo'),
|
|
|
|
watchContentBase: true,
|
|
|
|
compress: true,
|
2016-08-28 21:46:10 +03:00
|
|
|
watchOptions: {
|
|
|
|
poll: true
|
|
|
|
},
|
|
|
|
port: 9000,
|
2016-08-30 19:53:06 +03:00
|
|
|
hot: false,
|
|
|
|
stats: 'errors-only'
|
2016-08-28 21:46:10 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
output: {
|
|
|
|
path: root('dist'),
|
|
|
|
filename: '[name].js',
|
2016-08-30 19:53:06 +03:00
|
|
|
sourceMapFilename: '[name].[id].map',
|
2016-11-01 10:57:06 +03:00
|
|
|
chunkFilename: '[id].chunk.js',
|
|
|
|
// devtoolModuleFilenameTemplate: "[resource-path]",
|
|
|
|
// devtoolFallbackModuleFilenameTemplate: "[resource-path]?[hash]",
|
2016-08-28 21:46:10 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
module: {
|
2016-09-28 00:30:33 +03:00
|
|
|
exprContextCritical: false,
|
|
|
|
rules: [{
|
2016-09-27 09:03:04 +03:00
|
|
|
enforce: 'pre',
|
2016-08-30 19:53:06 +03:00
|
|
|
test: /\.js$/,
|
2016-09-02 23:24:51 +03:00
|
|
|
loader: 'source-map-loader',
|
|
|
|
exclude: [
|
|
|
|
/node_modules/
|
|
|
|
]
|
2016-10-31 12:03:15 +03:00
|
|
|
}, {
|
|
|
|
enforce: 'pre',
|
|
|
|
test: /\.ts$/,
|
|
|
|
exclude: [
|
|
|
|
/node_modules/
|
|
|
|
],
|
|
|
|
loader: StringReplacePlugin.replace({
|
|
|
|
replacements: [
|
|
|
|
{
|
|
|
|
pattern: /styleUrls:\s*\[\s*'([\w\.\/-]*)\.css'\s*\][\s,]*$/m,
|
|
|
|
replacement: function (match, p1, offset, string) {
|
|
|
|
return `styleUrls: ['${p1}.scss'],`;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: /(\.\/components\/Redoc\/redoc-initial-styles\.css)/m,
|
|
|
|
replacement: function (match, p1, offset, string) {
|
|
|
|
return p1.replace('.css', '.scss');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
2016-09-27 09:03:04 +03:00
|
|
|
}, {
|
2016-08-28 21:46:10 +03:00
|
|
|
test: /\.ts$/,
|
|
|
|
loaders: [
|
|
|
|
'awesome-typescript-loader',
|
|
|
|
'angular2-template-loader'
|
|
|
|
],
|
|
|
|
exclude: [/\.(spec|e2e)\.ts$/]
|
2016-09-27 09:03:04 +03:00
|
|
|
}, {
|
2016-10-31 12:03:15 +03:00
|
|
|
test: /lib[\\\/].*\.scss$/,
|
2016-11-29 10:20:11 +03:00
|
|
|
loaders: ['raw-loader', "sass-loader"],
|
2016-10-31 12:03:15 +03:00
|
|
|
exclude: [/redoc-initial-styles\.scss$/]
|
|
|
|
}, {
|
|
|
|
test: /\.scss$/,
|
2016-11-29 10:20:11 +03:00
|
|
|
loaders: ['style-loader', 'css-loader?-import', "sass-loader"],
|
2016-10-31 12:03:15 +03:00
|
|
|
exclude: [/lib[\\\/](?!.*redoc-initial-styles).*\.scss$/]
|
2016-09-27 09:03:04 +03:00
|
|
|
}, {
|
2016-08-28 21:46:10 +03:00
|
|
|
test: /\.css$/,
|
2016-11-29 10:20:11 +03:00
|
|
|
loaders: ['style-loader', 'css-loader?-import'],
|
2016-09-27 09:03:04 +03:00
|
|
|
}, {
|
2016-08-28 21:46:10 +03:00
|
|
|
test: /\.html$/,
|
|
|
|
loader: 'raw-loader'
|
|
|
|
}]
|
|
|
|
},
|
|
|
|
|
|
|
|
plugins: [
|
|
|
|
new webpack.HotModuleReplacementPlugin(),
|
|
|
|
|
|
|
|
new webpack.optimize.CommonsChunkPlugin({
|
|
|
|
name: ['vendor', 'polyfills'],
|
|
|
|
minChunks: Infinity
|
|
|
|
}),
|
|
|
|
|
|
|
|
new webpack.DefinePlugin({
|
2016-08-30 19:53:06 +03:00
|
|
|
'IS_PRODUCTION': IS_PRODUCTION,
|
2016-09-28 00:30:33 +03:00
|
|
|
'LIB_VERSION': VERSION,
|
|
|
|
'AOT': IS_PRODUCTION
|
2016-08-28 21:46:10 +03:00
|
|
|
}),
|
|
|
|
|
2016-10-31 12:03:15 +03:00
|
|
|
new ForkCheckerPlugin(),
|
|
|
|
|
|
|
|
new StringReplacePlugin()
|
2016-08-28 21:46:10 +03:00
|
|
|
],
|
|
|
|
}
|