232 lines
5.2 KiB
JavaScript
232 lines
5.2 KiB
JavaScript
const webpack = require('webpack');
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin');
|
|
const TerserPlugin = require('terser-webpack-plugin');
|
|
|
|
|
|
const path = require('path');
|
|
|
|
function resolvePath(dir) {
|
|
return path.join(__dirname, '..', dir);
|
|
}
|
|
|
|
const env = process.env.NODE_ENV || 'development';
|
|
const target = process.env.TARGET || 'web';
|
|
|
|
|
|
|
|
module.exports = {
|
|
mode: env,
|
|
entry: {
|
|
app: './src/js/app.js',
|
|
},
|
|
output: {
|
|
path: resolvePath('./'),
|
|
filename: 'js/[name].js',
|
|
chunkFilename: 'js/[name].js',
|
|
publicPath: '',
|
|
hotUpdateChunkFilename: 'hot/hot-update.js',
|
|
hotUpdateMainFilename: 'hot/hot-update.json',
|
|
},
|
|
resolve: {
|
|
extensions: ['.js', '.jsx', '.json'],
|
|
alias: {
|
|
|
|
'@': resolvePath('src'),
|
|
},
|
|
|
|
},
|
|
watch: true,
|
|
watchOptions: {
|
|
aggregateTimeout: 600,
|
|
poll: 1000,
|
|
},
|
|
externals: {
|
|
jquery: 'jQuery'
|
|
},
|
|
devtool: env === 'production' ? 'source-map' : 'source-map',
|
|
devServer: {
|
|
hot: true,
|
|
open: false,
|
|
compress: true,
|
|
contentBase: '/www/',
|
|
disableHostCheck: true,
|
|
historyApiFallback: true,
|
|
watchOptions: {
|
|
poll: 1000,
|
|
},
|
|
},
|
|
optimization: {
|
|
minimizer: [new TerserPlugin({
|
|
sourceMap: true,
|
|
})],
|
|
},
|
|
module: {
|
|
rules: [
|
|
{
|
|
test: /\.(mjs|js|jsx)$/,
|
|
use: 'babel-loader',
|
|
include: [
|
|
resolvePath('src'),
|
|
resolvePath('node_modules/framework7'),
|
|
|
|
resolvePath('node_modules/framework7-react'),
|
|
|
|
resolvePath('node_modules/template7'),
|
|
resolvePath('node_modules/dom7'),
|
|
resolvePath('node_modules/ssr-window'),
|
|
],
|
|
},
|
|
|
|
|
|
|
|
{
|
|
test: /\.css$/,
|
|
use: [
|
|
(env === 'development' ? 'style-loader' : {
|
|
loader: MiniCssExtractPlugin.loader,
|
|
options: {
|
|
publicPath: '../www'
|
|
}
|
|
}),
|
|
'css-loader',
|
|
'postcss-loader',
|
|
],
|
|
},
|
|
{
|
|
test: /\.styl(us)?$/,
|
|
use: [
|
|
(env === 'development' ? 'style-loader' : {
|
|
loader: MiniCssExtractPlugin.loader,
|
|
options: {
|
|
publicPath: '../www'
|
|
}
|
|
}),
|
|
'css-loader',
|
|
'postcss-loader',
|
|
'stylus-loader',
|
|
],
|
|
},
|
|
{
|
|
test: /\.less$/,
|
|
use: [
|
|
(env === 'development' ? 'style-loader' : {
|
|
loader: MiniCssExtractPlugin.loader,
|
|
options: {
|
|
publicPath: '../www'
|
|
}
|
|
}),
|
|
'css-loader',
|
|
'postcss-loader',
|
|
'less-loader',
|
|
],
|
|
},
|
|
{
|
|
test: /\.(sa|sc)ss$/,
|
|
use: [
|
|
(env === 'development' ? 'style-loader' : {
|
|
loader: MiniCssExtractPlugin.loader,
|
|
options: {
|
|
publicPath: '../www'
|
|
}
|
|
}),
|
|
'css-loader',
|
|
'postcss-loader',
|
|
'sass-loader',
|
|
],
|
|
},
|
|
{
|
|
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
|
|
loader: 'url-loader',
|
|
options: {
|
|
limit: 10000,
|
|
name: 'images/[name].[ext]',
|
|
|
|
},
|
|
},
|
|
{
|
|
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac|m4a)(\?.*)?$/,
|
|
loader: 'url-loader',
|
|
options: {
|
|
limit: 10000,
|
|
name: 'media/[name].[ext]',
|
|
|
|
},
|
|
},
|
|
{
|
|
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
|
|
loader: 'url-loader',
|
|
options: {
|
|
limit: 10000,
|
|
name: 'fonts/[name].[ext]',
|
|
|
|
},
|
|
},
|
|
{
|
|
test: /jquery.+\.js$/,
|
|
use: [{
|
|
loader: 'expose-loader',
|
|
options: 'jQuery'
|
|
},{
|
|
loader: 'expose-loader',
|
|
options: '$'
|
|
}]
|
|
},
|
|
|
|
],
|
|
},
|
|
plugins: [
|
|
new webpack.DefinePlugin({
|
|
'process.env.NODE_ENV': JSON.stringify(env),
|
|
'process.env.TARGET': JSON.stringify(target),
|
|
}),
|
|
|
|
...(env === 'production' ? [
|
|
new OptimizeCSSPlugin({
|
|
cssProcessorOptions: {
|
|
safe: true,
|
|
map: { inline: false },
|
|
},
|
|
}),
|
|
new webpack.optimize.ModuleConcatenationPlugin(),
|
|
] : [
|
|
// Development only plugins
|
|
new webpack.HotModuleReplacementPlugin(),
|
|
new webpack.NamedModulesPlugin(),
|
|
]),
|
|
new HtmlWebpackPlugin({
|
|
filename: './index.html',
|
|
template: './index_dev.html',
|
|
inject: true,
|
|
minify: env === 'production' ? {
|
|
collapseWhitespace: true,
|
|
removeComments: true,
|
|
removeRedundantAttributes: true,
|
|
removeScriptTypeAttributes: true,
|
|
removeStyleLinkTypeAttributes: true,
|
|
useShortDoctype: true
|
|
} : false,
|
|
}),
|
|
new MiniCssExtractPlugin({
|
|
filename: 'css/[name].css',
|
|
}),
|
|
new CopyWebpackPlugin({
|
|
patterns: [
|
|
{
|
|
noErrorOnMissing: true,
|
|
from: resolvePath('src/static'),
|
|
to: resolvePath('www/static'),
|
|
},
|
|
|
|
],
|
|
}),
|
|
new webpack.ProvidePlugin({
|
|
$: "jquery",
|
|
jQuery: "jquery"
|
|
}),
|
|
|
|
],
|
|
}; |