salix/webpack.config.js

158 lines
4.1 KiB
JavaScript
Raw Permalink Normal View History

require('require-yaml');
const webpack = require('webpack');
const path = require('path');
const merge = require('webpack-merge');
2018-12-27 11:54:16 +00:00
const HtmlWebpackPlugin = require('html-webpack-plugin');
let env = process.env.NODE_ENV || 'development';
let mode = env == 'development' ? env : 'production';
let baseConfig = {
2019-01-25 22:02:29 +00:00
entry: {salix: 'salix'},
2023-06-08 08:25:25 +00:00
mode,
output: {
2024-02-06 20:51:15 +00:00
path: path.join(__dirname, 'front/dist'),
2019-01-25 22:02:29 +00:00
publicPath: '/'
},
module: {
2018-02-08 12:47:54 +00:00
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
2023-05-23 11:31:09 +00:00
options: {
presets: ['@babel/preset-env'],
plugins: ['@babel/plugin-syntax-dynamic-import']
}
}, {
test: /\.yml$/,
2023-05-23 11:31:09 +00:00
use: ['json-loader!yaml-loader']
}, {
test: /\.html$/,
2019-02-05 08:13:15 +00:00
loader: 'html-loader',
options: {
attrs: [
'img:src',
'link:href'
]
}
}, {
test: /\.css$/,
2023-05-23 11:31:09 +00:00
use: ['style-loader', 'css-loader']
}, {
test: /\.scss$/,
use: [
2023-05-23 11:31:09 +00:00
'style-loader', 'css-loader', {
loader: 'sass-loader',
options: {
2019-10-14 10:01:19 +00:00
// XXX: Don't work in Firefox
2019-02-06 10:24:29 +00:00
// https://github.com/webpack-contrib/style-loader/issues/303
// sourceMap: true,
2023-05-23 11:31:09 +00:00
sassOptions: {
includePaths: [
path.resolve(__dirname, 'front/core/styles/')
]
}
}
}
]
}, {
2023-05-23 11:31:09 +00:00
test: /\.(woff(2)?|ttf|eot|svg|png)(\?v=\d+\.\d+\.\d+)?$/,
type: 'asset/resource',
2019-02-05 08:13:15 +00:00
}, {
test: /manifest\.json$/,
type: 'javascript/auto',
2023-05-23 12:43:15 +00:00
loader: 'file-loader',
2023-05-23 11:31:09 +00:00
options: {
esModule: false,
}
}
]
},
optimization: {
nodeEnv: false,
runtimeChunk: true,
splitChunks: {
chunks: 'all',
}
},
resolve: {
modules: [
2018-12-27 11:54:16 +00:00
`front`,
`modules`,
`front/node_modules`,
`node_modules`
2018-09-13 13:19:50 +00:00
],
alias: {
2018-12-27 11:54:16 +00:00
'vn-loopback': `${__dirname}/loopback`
2018-09-13 13:19:50 +00:00
}
},
2019-01-28 11:14:22 +00:00
watchOptions: {
ignored: [
'node_modules',
'./modules/*/back/**'
]
},
plugins: [
2018-12-27 11:54:16 +00:00
new HtmlWebpackPlugin({
template: 'front/salix/index.ejs',
2019-01-25 22:02:29 +00:00
favicon: 'front/salix/favicon.ico',
2018-12-27 11:54:16 +00:00
filename: 'index.html',
chunks: ['salix']
2019-10-23 15:38:35 +00:00
}),
],
devtool: 'source-map',
2019-01-28 11:16:22 +00:00
stats: {
assets: false,
2019-10-15 14:19:35 +00:00
modules: false,
2018-12-27 11:54:16 +00:00
children: false,
2019-01-28 11:16:22 +00:00
entrypoints: false,
colors: true
}
};
let prodConfig = {
output: {
filename: '[name].[chunkhash].js',
chunkFilename: '[id].[chunkhash].js'
},
plugins: [
2023-05-23 11:31:09 +00:00
new webpack.ids.HashedModuleIdsPlugin()
],
performance: {
maxEntrypointSize: 2000000,
maxAssetSize: 2000000
}
};
let devConfig = {
output: {
filename: '[name].js',
chunkFilename: '[id].js'
},
plugins: [
new webpack.HotModuleReplacementPlugin()
],
devServer: {
2019-02-01 08:31:01 +00:00
host: '0.0.0.0',
2019-01-25 22:02:29 +00:00
port: 5000,
publicPath: '/',
2024-02-06 20:51:15 +00:00
contentBase: 'front/dist',
quiet: false,
noInfo: false,
hot: true,
inline: true,
2019-01-25 22:02:29 +00:00
stats: baseConfig.stats,
proxy: {
'/api': 'http://localhost:3000',
'/*/api/**': {
target: 'http://localhost:3000',
pathRewrite: {'^/[\\w-]+': ''}
}
}
}
};
let mrgConfig = mode === 'development' ? devConfig : prodConfig;
module.exports = merge(baseConfig, mrgConfig);