-
-
Save moranm6/b59e5c0003fedca665301f54f32d7da4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const webpack = require('webpack'); | |
const ExtractTextPlugin = require('extract-text-webpack-plugin'); | |
const { CheckerPlugin } = require('awesome-typescript-loader'); | |
const HtmlWebpackPlugin = require('html-webpack-plugin'); | |
const isProduction = process.env.NODE_ENV === 'production'; | |
const modifyConfigForEnvironment = isProduction ? | |
require('./config/webpack.config.prod') : | |
require('./config/webpack.config.dev'); | |
const cssLoaders = cssLoaderConfig(); | |
const extractStyles = extractStylesPlugin(isProduction); | |
const commonConfig = { | |
entry: { | |
app: './src/modules/app/index.tsx' | |
}, | |
output: { | |
filename: '[name].bundle.js', | |
publicPath: '', | |
path: __dirname + '/build', //dist | |
}, | |
resolve: { | |
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json', '.css', '.scss', '.ttf', '.woff', '.woff2', '.svg', '.gif', '.png'], | |
alias: { | |
'@module': path.resolve(__dirname, "src/modules"), | |
'@service': path.resolve(__dirname, "src/services"), | |
'@util': path.resolve(__dirname, "src/utils"), | |
moment$: 'moment/moment.js', | |
}, | |
modules: ["node_modules", path.resolve(__dirname, 'node_modules/@abb/common-ux/dist/assets'), path.resolve(__dirname, 'src/modules/app/assets'), | |
path.resolve(__dirname, 'node_modules/@abb/abb-common-ux-react')] | |
}, | |
module: { | |
rules: [ | |
{ | |
enforce: 'pre', | |
test: /\.tsx?$/, | |
loader: 'tslint-loader', | |
exclude: /(node_modules)/, | |
options: { | |
emitErrors: true, | |
failOnHint: true, | |
configFile: 'tslint.json', | |
tsConfigFile: 'tsconfig.json' | |
} | |
}, | |
{ | |
test: /\.tsx?$/, | |
exclude: /(node_modules)/, | |
loader: 'awesome-typescript-loader' | |
}, | |
{ | |
test: /\.css$/, | |
use: extractStyles.extract({ | |
fallback: 'style-loader', | |
use: cssLoaders | |
}) | |
}, | |
{ | |
test: /\.scss$/, | |
use: extractStyles.extract({ | |
fallback: 'style-loader', | |
use: [ | |
...cssLoaders, | |
{ | |
loader: 'sass-loader', | |
options: { | |
sourceMap: true, | |
convertToAbsoluteUrls: true, | |
precision: 8 | |
} | |
}, | |
] | |
}) | |
}, | |
{ | |
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/, | |
loader: 'url-loader', | |
options: { | |
limit: 10000, | |
name: '[name].[ext]' | |
} | |
} | |
] | |
}, | |
watch: true, | |
plugins: [ | |
new CheckerPlugin(), | |
new HtmlWebpackPlugin({ | |
template: path.resolve(__dirname, 'src/modules/app/index.template.html'), | |
// excludeChunks: ['common-ux'], | |
inject: 'body', | |
}), | |
extractStyles, | |
new webpack.DefinePlugin({ | |
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development') | |
}), | |
] | |
}; | |
module.exports = modifyConfigForEnvironment(commonConfig, __dirname); | |
function cssLoaderConfig() { | |
return [ | |
{ | |
loader: 'css-loader', | |
options: { | |
sourceMap: true, | |
importLoaders: 1 | |
} | |
} | |
// { | |
// loader: 'postcss-loader', | |
// options: { | |
// sourceMap: true, | |
// plugins: function () { | |
// return [ | |
// require('precss'), | |
// require('autoprefixer') | |
// ]; | |
// } | |
// } | |
// } | |
]; | |
} | |
function extractStylesPlugin(isProduction) { | |
return new ExtractTextPlugin({ | |
filename: "[name].[contenthash].css", | |
disable: !isProduction | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment