2016-09-22 15:54:26 +02:00
|
|
|
var webpack = require('webpack');
|
|
|
|
var path = require('path');
|
2016-11-22 14:36:12 +01:00
|
|
|
var clone = require('js.clone');
|
|
|
|
var webpackMerge = require('webpack-merge');
|
|
|
|
|
|
|
|
export var commonPlugins = [
|
|
|
|
new webpack.ContextReplacementPlugin(
|
|
|
|
// The (\\|\/) piece accounts for path separators in *nix and Windows
|
|
|
|
/angular(\\|\/)core(\\|\/)src(\\|\/)linker/,
|
|
|
|
root('./src'),
|
|
|
|
{
|
|
|
|
// your Angular Async Route paths relative to this root directory
|
|
|
|
}
|
|
|
|
),
|
|
|
|
|
|
|
|
// Loader options
|
|
|
|
new webpack.LoaderOptionsPlugin({
|
|
|
|
|
|
|
|
}),
|
2016-09-22 15:54:26 +02:00
|
|
|
|
2016-11-22 14:36:12 +01:00
|
|
|
];
|
|
|
|
export var commonConfig = {
|
|
|
|
// https://webpack.github.io/docs/configuration.html#devtool
|
|
|
|
devtool: 'source-map',
|
2016-09-22 15:54:26 +02:00
|
|
|
resolve: {
|
2016-11-22 14:36:12 +01:00
|
|
|
extensions: ['.ts', '.js', '.json'],
|
|
|
|
modules: [ root('node_modules') ]
|
|
|
|
},
|
|
|
|
context: __dirname,
|
|
|
|
output: {
|
|
|
|
publicPath: '',
|
|
|
|
filename: '[name].bundle.js'
|
2016-09-22 15:54:26 +02:00
|
|
|
},
|
|
|
|
module: {
|
2016-11-22 14:36:12 +01:00
|
|
|
rules: [
|
2016-09-22 15:54:26 +02:00
|
|
|
// TypeScript
|
2016-11-22 14:36:12 +01:00
|
|
|
{ test: /\.ts$/, use: ['awesome-typescript-loader', 'angular2-template-loader'] },
|
|
|
|
{ test: /\.html$/, use: 'raw-loader' },
|
|
|
|
{ test: /\.css$/, use: 'raw-loader' },
|
|
|
|
{ test: /\.json$/, use: 'json-loader' }
|
2016-09-22 15:54:26 +02:00
|
|
|
],
|
|
|
|
},
|
|
|
|
plugins: [
|
2016-11-22 14:36:12 +01:00
|
|
|
// Use commonPlugins.
|
2016-09-22 15:54:26 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-11-22 14:36:12 +01:00
|
|
|
// Client.
|
|
|
|
export var clientPlugins = [
|
2016-09-22 15:54:26 +02:00
|
|
|
|
2016-11-22 14:36:12 +01:00
|
|
|
];
|
|
|
|
export var clientConfig = {
|
2016-09-22 15:54:26 +02:00
|
|
|
target: 'web',
|
|
|
|
entry: './src/client',
|
|
|
|
output: {
|
|
|
|
path: root('dist/client')
|
|
|
|
},
|
|
|
|
node: {
|
|
|
|
global: true,
|
2016-11-22 14:36:12 +01:00
|
|
|
crypto: 'empty',
|
2016-09-22 15:54:26 +02:00
|
|
|
__dirname: true,
|
|
|
|
__filename: true,
|
|
|
|
process: true,
|
|
|
|
Buffer: false
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-11-22 14:36:12 +01:00
|
|
|
// Server.
|
|
|
|
export var serverPlugins = [
|
|
|
|
|
|
|
|
];
|
|
|
|
export var serverConfig = {
|
2016-09-22 15:54:26 +02:00
|
|
|
target: 'node',
|
|
|
|
entry: './src/server', // use the entry file of the node server if everything is ts rather than es5
|
|
|
|
output: {
|
2016-11-22 14:36:12 +01:00
|
|
|
filename: 'index.js',
|
2016-09-22 15:54:26 +02:00
|
|
|
path: root('dist/server'),
|
|
|
|
libraryTarget: 'commonjs2'
|
|
|
|
},
|
|
|
|
module: {
|
2016-11-22 14:36:12 +01:00
|
|
|
rules: [
|
|
|
|
{ test: /@angular(\\|\/)material/, use: "imports-loader?window=>global" }
|
2016-09-22 15:54:26 +02:00
|
|
|
],
|
|
|
|
},
|
2016-11-22 14:36:12 +01:00
|
|
|
externals: includeClientPackages(
|
|
|
|
/@angularclass|@angular|angular2-|ng2-|ng-|@ng-|angular-|@ngrx|ngrx-|@angular2|ionic|@ionic|-angular2|-ng2|-ng/
|
|
|
|
),
|
2016-09-22 15:54:26 +02:00
|
|
|
node: {
|
|
|
|
global: true,
|
2016-11-22 14:36:12 +01:00
|
|
|
crypto: true,
|
2016-09-22 15:54:26 +02:00
|
|
|
__dirname: true,
|
|
|
|
__filename: true,
|
|
|
|
process: true,
|
2016-11-29 11:42:17 +01:00
|
|
|
Buffer: true
|
2017-02-10 14:15:53 +01:00
|
|
|
}
|
2016-09-22 15:54:26 +02:00
|
|
|
};
|
|
|
|
|
2016-11-22 14:36:12 +01:00
|
|
|
export default [
|
2016-09-22 15:54:26 +02:00
|
|
|
// Client
|
2016-11-22 14:36:12 +01:00
|
|
|
webpackMerge(clone(commonConfig), clientConfig, { plugins: clientPlugins.concat(commonPlugins) }),
|
2016-09-22 15:54:26 +02:00
|
|
|
|
|
|
|
// Server
|
2016-11-22 14:36:12 +01:00
|
|
|
webpackMerge(clone(commonConfig), serverConfig, { plugins: serverPlugins.concat(commonPlugins) })
|
2016-09-22 15:54:26 +02:00
|
|
|
];
|
|
|
|
|
2016-11-22 14:36:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Helpers
|
|
|
|
export function includeClientPackages(packages, localModule?: string[]) {
|
2016-09-22 15:54:26 +02:00
|
|
|
return function(context, request, cb) {
|
2016-11-22 14:36:12 +01:00
|
|
|
if (localModule instanceof RegExp && localModule.test(request)) {
|
2016-09-22 15:54:26 +02:00
|
|
|
return cb();
|
|
|
|
}
|
2016-11-22 14:36:12 +01:00
|
|
|
if (packages instanceof RegExp && packages.test(request)) {
|
|
|
|
return cb();
|
|
|
|
}
|
|
|
|
if (Array.isArray(packages) && packages.indexOf(request) !== -1) {
|
|
|
|
return cb();
|
|
|
|
}
|
|
|
|
if (!path.isAbsolute(request) && request.charAt(0) !== '.') {
|
|
|
|
return cb(null, 'commonjs ' + request);
|
|
|
|
}
|
|
|
|
return cb();
|
2016-09-22 15:54:26 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-11-22 14:36:12 +01:00
|
|
|
export function root(args) {
|
2016-09-22 15:54:26 +02:00
|
|
|
args = Array.prototype.slice.call(arguments, 0);
|
|
|
|
return path.join.apply(path, [__dirname].concat(args));
|
|
|
|
}
|