2017-01-06 22:38:04 +03:00
|
|
|
const webpack = require('webpack');
|
|
|
|
|
|
|
|
const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin;
|
|
|
|
const StringReplacePlugin = require("string-replace-webpack-plugin");
|
|
|
|
const CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin');
|
|
|
|
|
|
|
|
const VERSION = JSON.stringify(require('../package.json').version);
|
|
|
|
|
|
|
|
const root = require('./helpers').root;
|
|
|
|
|
|
|
|
module.exports = function (options) {
|
|
|
|
const conf = {
|
|
|
|
performance: { hints: false },
|
|
|
|
|
|
|
|
output: {
|
|
|
|
path: root('dist'),
|
|
|
|
filename: '[name].js',
|
|
|
|
sourceMapFilename: '[name].[id].map',
|
|
|
|
chunkFilename: '[id].chunk.js'
|
|
|
|
},
|
|
|
|
|
|
|
|
resolve: {
|
|
|
|
extensions: ['.ts', '.js', '.json', '.css'],
|
|
|
|
alias: {
|
|
|
|
http: 'stream-http',
|
2017-04-10 10:50:21 +03:00
|
|
|
https: 'https-browserify'
|
2017-01-06 22:38:04 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
externals: {
|
|
|
|
'jquery': 'jquery',
|
|
|
|
'esprima': 'esprima' // optional dep of ys-yaml not needed for redoc
|
|
|
|
},
|
|
|
|
|
|
|
|
module: {
|
|
|
|
exprContextCritical: false,
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
enforce: 'pre',
|
|
|
|
test: /\.ts$/,
|
|
|
|
exclude: [
|
|
|
|
/node_modules/
|
|
|
|
],
|
|
|
|
loader: StringReplacePlugin.replace({
|
|
|
|
replacements: [
|
|
|
|
{
|
|
|
|
pattern: /styleUrls:\s*\[\s*'([\w\.\/-]*)\.css'\s*\][\s,]*$/gm,
|
|
|
|
replacement: function (match, p1, offset, string) {
|
|
|
|
return `styleUrls: ['${p1}.scss'],`;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: /(\.\/components\/Redoc\/redoc-initial-styles\.css)/gm,
|
|
|
|
replacement: function (match, p1, offset, string) {
|
|
|
|
return p1.replace('.css', '.scss');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
},
|
|
|
|
{
|
|
|
|
enforce: 'pre',
|
|
|
|
test: /\.js$/,
|
|
|
|
loader: 'source-map-loader',
|
|
|
|
exclude: [
|
|
|
|
/node_modules/
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.json$/,
|
|
|
|
use: 'json-loader'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /lib[\\\/].*\.css$/,
|
|
|
|
loaders: ['raw-loader'],
|
|
|
|
exclude: [/redoc-initial-styles\.css$/]
|
|
|
|
}, {
|
|
|
|
test: /\.css$/,
|
|
|
|
loaders: ['style-loader', 'css-loader?-import'],
|
|
|
|
exclude: [/lib[\\\/](?!.*redoc-initial-styles).*\.css$/]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /lib[\\\/].*\.scss$/,
|
2017-02-26 00:32:18 +03:00
|
|
|
loaders: ['raw-loader', 'sass-loader'],
|
2017-01-06 22:38:04 +03:00
|
|
|
exclude: [/redoc-initial-styles\.scss$/]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.scss$/,
|
2017-02-14 13:01:09 +03:00
|
|
|
use: [
|
|
|
|
'style-loader',
|
|
|
|
'css-loader?-import',
|
|
|
|
'sass-loader'
|
|
|
|
],
|
2017-01-06 22:38:04 +03:00
|
|
|
exclude: [/lib[\\\/](?!.*redoc-initial-styles).*\.scss$/]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.html$/,
|
|
|
|
loader: 'raw-loader'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
plugins: [
|
|
|
|
new CheckerPlugin(),
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
'IS_PRODUCTION': options.IS_PRODUCTION,
|
|
|
|
'LIB_VERSION': VERSION,
|
|
|
|
'AOT': options.AOT
|
|
|
|
}),
|
|
|
|
|
2017-03-01 01:07:04 +03:00
|
|
|
new StringReplacePlugin()
|
2017-01-06 22:38:04 +03:00
|
|
|
],
|
|
|
|
node: {
|
|
|
|
global: true,
|
|
|
|
crypto: 'empty',
|
|
|
|
fs: 'empty',
|
|
|
|
process: true,
|
|
|
|
module: false,
|
|
|
|
clearImmediate: false,
|
|
|
|
setImmediate: false
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-03-15 18:51:04 +03:00
|
|
|
// if (options.AOT) {
|
|
|
|
// conf.plugins.push(
|
|
|
|
// new ngcWebpack.NgcWebpackPlugin({
|
|
|
|
// disable: !options.AOT,
|
|
|
|
// tsConfig: root('tsconfig.webpack.json'),
|
|
|
|
// resourceOverride: root('build/resource-override.js')
|
|
|
|
// })
|
|
|
|
// );
|
|
|
|
// }
|
2017-01-06 22:38:04 +03:00
|
|
|
|
|
|
|
return conf;
|
|
|
|
}
|