portainer/webpack/webpack.common.js

113 lines
2.8 KiB
JavaScript
Raw Normal View History

const path = require('path');
2018-11-12 19:56:51 +00:00
const { ProvidePlugin, IgnorePlugin } = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const WebpackBuildNotifierPlugin = require('webpack-build-notifier');
const CleanTerminalPlugin = require('clean-terminal-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
// const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
2018-11-12 19:56:51 +00:00
const LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
const npmPackage = require('../package.json');
const projectRoot = path.resolve(__dirname, '..');
module.exports = {
entry: {
main: './app/__module.js'
},
output: {
filename: '[name].[hash].js',
path: path.resolve(projectRoot, 'dist/public')
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: [
'babel-loader',
'auto-ngtemplate-loader',
{
// enforce: 'pre',
loader: 'eslint-loader'
}
]
},
{
test: /\.html$/,
exclude: path.resolve(projectRoot, './app/index.html'),
use: [
{
loader: 'ngtemplate-loader',
options: {
relativeTo: projectRoot
}
},
{ loader: 'html-loader' }
]
},
2018-12-09 12:25:52 +00:00
{
test: /.xml$/,
use: 'file-loader'
},
{
test: /\.css$/,
2018-11-26 14:25:00 +00:00
use: [
MiniCssExtractPlugin.loader,
{ loader: 'css-loader', options: { importLoaders: 1 } },
'postcss-loader'
]
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: './app/index.html',
templateParameters: {
name: npmPackage.name,
author: npmPackage.author
},
manifest: './assets/ico/manifest.json'
}),
new WebpackBuildNotifierPlugin({
title: 'Portainer build',
logo: path.resolve('./assets/favicon-32x32.png'),
suppressSuccess: true
}),
new CleanTerminalPlugin(),
new ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
2018-12-09 12:25:52 +00:00
'window.moment': 'moment',
moment: 'moment',
'window.jsyaml': 'js-yaml',
2018-12-09 12:25:52 +00:00
jsyaml: 'js-yaml'
}),
new MiniCssExtractPlugin({
2018-11-26 14:25:00 +00:00
filename: '[name].[hash].css',
2018-12-03 11:20:49 +00:00
chunkFilename: '[name].[id].css',
sourceMap: true
}),
new CleanWebpackPlugin(['dist/public']),
2018-11-12 19:56:51 +00:00
new IgnorePlugin(/^\.\/locale$/, /moment$/),
// new BundleAnalyzerPlugin()
2018-11-29 07:54:26 +00:00
new LodashModuleReplacementPlugin({
shorthands: true
})
],
optimization: {
splitChunks: {
cacheGroups: {
vendor: {
test: /node_modules/,
chunks: 'initial',
name: 'vendor',
priority: 10,
enforce: true
}
}
}
}
};