webpack-bootstrap-ui-kit/webpack.config.js

201 lines
4.4 KiB
JavaScript
Raw Normal View History

2019-10-20 04:40:30 +02:00
const COMPRESS = false;
2019-06-08 17:20:51 +02:00
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
const path = require('path');
const autoprefixer = require('autoprefixer');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
2019-10-20 03:19:20 +02:00
const TerserPlugin = require('terser-webpack-plugin');
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
2019-06-08 17:20:51 +02:00
2019-10-20 04:40:30 +02:00
const plugins = [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production')
}
}),
new webpack.LoaderOptionsPlugin({
minimize: COMPRESS,
debug: false
}),
new ExtractTextPlugin({
filename: 'css/[name].css',
allChunks: true
}),
/**/
new HtmlWebpackPlugin({
template: './src/index.html'
}),
];
if (COMPRESS) {
plugins.push(new OptimizeCssAssetsPlugin({
//assetNameRegExp: /\.optimize\.css$/g,
cssProcessor: require('cssnano'),
cssProcessorPluginOptions: {
preset: ['default', {
discardComments: {
removeAll: true
}
}],
},
canPrint: true
}));
}
2019-06-08 17:20:51 +02:00
module.exports = {
entry: './src/js/app.js',
output: {
path: path.resolve(__dirname, 'dist'),
2019-06-08 17:57:04 +02:00
filename: 'js/app.js'
2019-06-08 17:20:51 +02:00
},
2019-10-20 04:40:30 +02:00
devtool: (COMPRESS ? '' : 'source-map'),
2019-06-08 17:20:51 +02:00
externals: {
'jquery': 'jQuery',
},
optimization: {
namedModules: true, // NamedModulesPlugin()
splitChunks: { // CommonsChunkPlugin()
name: 'vendor',
minChunks: 2
},
noEmitOnErrors: true, // NoEmitOnErrorsPlugin
concatenateModules: true, //ModuleConcatenationPlugin
minimizer: [
2019-10-20 03:19:20 +02:00
new TerserPlugin({
parallel: true,
2019-10-20 04:40:30 +02:00
sourceMap: !COMPRESS,
2019-10-20 03:19:20 +02:00
terserOptions: {
parse: {
ecma: 8,
},
output: {
ecma: 5,
},
},
}),
2019-06-08 17:20:51 +02:00
]
},
module: {
rules: [{
test: /\.jsx?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [
['es2015', {
modules: false,
}],
['stage-2'],
],
plugins: [
['transform-react-jsx'],
['react-hot-loader/babel'],
],
},
},
}, {
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
}, {
test: /\.coffee?$/,
use: 'coffee-loader',
}, {
test: /\.worker\.js$/,
use: {
loader: 'worker-loader',
},
}, {
test: /\.s?css$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: [{
loader: 'css-loader',
options: {
2019-10-20 04:40:30 +02:00
sourceMap: !COMPRESS
2019-06-08 17:20:51 +02:00
}
}, {
loader: 'postcss-loader',
options: {
2019-10-20 04:40:30 +02:00
sourceMap: !COMPRESS,
2019-06-08 17:20:51 +02:00
plugins: [
2019-11-25 07:02:37 +01:00
autoprefixer()
2019-06-08 17:20:51 +02:00
]
}
}, {
loader: 'resolve-url-loader'
}, {
loader: 'sass-loader',
options: {
2019-10-20 04:40:30 +02:00
sourceMap: !COMPRESS
2019-06-08 17:20:51 +02:00
}
}, ]
})
}, {
test: /fontawesome([^.]+).(ttf|otf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'fonts/',
publicPath: '../fonts/'
}
}]
}, {
test: /\.(ttf|otf|eot|svg|woff(2)?)$/,
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'fonts/',
publicPath: '../fonts/'
}
}]
}, {
test: /\.(png|jpg|jpeg|gif|svg)$/,
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'img/',
publicPath: '../img/'
},
}, ],
},
resolve: {
modules: [
path.resolve(__dirname, 'src'),
path.resolve(__dirname, 'node_modules'),
],
alias: {
'jquery': require.resolve('jquery'),
'jQuery': require.resolve('jquery'),
},
},
2019-10-20 04:40:30 +02:00
plugins: plugins,
2019-06-08 17:20:51 +02:00
devServer: {
host: '127.0.0.1',
port: 8001,
historyApiFallback: true,
hot: false,
clientLogLevel: 'info',
contentBase: [
path.resolve(__dirname, 'src'),
path.resolve(__dirname, 'node_modules'),
path.resolve(__dirname, 'dist'),
],
//watchContentBase: true,
overlay: {
warnings: true,
errors: true
},
headers: {
'Access-Control-Allow-Origin': '*',
}
},
};