alfresco-ng2-components/lib/config/webpack.common.js
Eugenio Romano ff2e855aa3
Fix prefix adf- import (#2657)
* fix prefix adf- import

* missing conf file prefix replacement

* fix demo shell start
2017-11-17 02:46:31 +00:00

174 lines
5.5 KiB
JavaScript

const webpack = require('webpack');
const helpers = require('./helpers');
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
var HappyPack = require('happypack');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const alfrescoLibs = [
'content-services',
'process-services',
'core'
];
const ENV = process.env.NODE_ENV = process.env.ENV = 'production';
module.exports = {
devtool: 'source-map',
resolveLoader: {
alias: {
"file-multi-loader": path.resolve(__dirname, "./custom-loaders/file-loader-multi"),
"license-check": path.resolve(__dirname, "./custom-loaders/license-check")
}
},
resolve: {
alias: {
"@alfresco/adf-content-services": path.resolve(__dirname, '../content-services/'),
"@alfresco/adf-content-services$": path.resolve(__dirname, '../content-services/index.ts'),
"@alfresco/adf-process-services": path.resolve(__dirname, '../process-services/'),
"@alfresco/adf-process-services$": path.resolve(__dirname, '../process-services/index.ts'),
"@alfresco/adf-core": path.resolve(__dirname, '../core/'),
"@alfresco/adf-core$": path.resolve(__dirname, '../core/index.ts'),
"@alfresco/adf-insights": path.resolve(__dirname, '../insights/'),
"@alfresco/adf-insights": path.resolve(__dirname, '../insights/index.ts')
},
extensions: ['.ts', '.js', '.scss'],
modules: [helpers.root('node_modules')]
},
module: {
rules: [
{
enforce: 'pre',
test: /\.js$/,
loader: 'source-map-loader',
exclude: [/node_modules/, /bundles/, /dist/, /demo/]
},
{
enforce: 'pre',
test: /\.ts$/,
use: 'source-map-loader',
exclude: [/node_modules/, /bundles/, /dist/, /demo/]
},
{
enforce: 'pre',
test: /\.ts$/,
loader: 'tslint-loader',
options: {
configFile : helpers.root('tslint.json'),
emitErrors: true,
failOnHint: true,
fix: true
},
exclude: [/node_modules/, /bundles/, /dist/, /demo/]
},
{
test: /\.ts$/,
loader: ['happypack/loader?id=ts', 'angular2-template-loader'],
exclude: [/node_modules/, /bundles/, /dist/, /demo/]
},
{
test: /\.html$/,
loader: 'html-loader',
exclude: [/node_modules/, /bundles/, /dist/, /demo/]
},
{
test: /\.css$/,
loader: ['happypack/loader?id=css'],
exclude: [/node_modules/, /bundles/, /dist/, /demo/]
},
{
test: /\.scss$/,
use: [{
loader: "to-string-loader"
}, {
loader: "raw-loader"
}, {
loader: "sass-loader"
}]
},
{
enforce: 'pre',
test: /\.ts$/,
loader: 'license-check',
options: {
emitErrors: true,
licenseFile: path.resolve(__dirname, './assets/license_header.txt')
},
exclude: [/node_modules/, /bundles/, /dist/, /demo/, /rendering-queue.services.ts/]
},
{
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
loader: 'file-multi-loader',
query: {
name: '[name].[hash].[ext]',
outputPath: (url, resourcePath)=> {
return resourcePath.replace('assets/', 'bundles/assets/') + url;
},
publicPath: (url, resourcePath)=> {
return resourcePath + url;
}
}
}
]
},
plugins: [
new ForkTsCheckerWebpackPlugin(),
new HappyPack({
id: 'ts',
threads: 4,
loaders: [
{
path: 'ts-loader',
query: {
happyPackMode: true,
"compilerOptions": {
"paths": {
}
}
}
}
]
}),
new HappyPack({
id: 'css',
threads: 4,
loaders: ['to-string-loader', 'css-loader' ]
}),
new CopyWebpackPlugin([
... alfrescoLibs.map(lib => {
return {
from: `${lib}/i18n/`,
to: `${lib}/bundles/assets/${lib}/i18n/`
}
})
]),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.ContextReplacementPlugin( /angular(\\|\/)core(\\|\/)/, path.resolve(__dirname, './src') ),
new webpack.DefinePlugin({
'process.env': {
'ENV': JSON.stringify(ENV)
}
}),
new webpack.LoaderOptionsPlugin({
htmlLoader: {
minimize: false // workaround for ng2
}
})
],
node: {
fs: 'empty',
module: false
}
};