salix/webpack.config.js

131 lines
3.3 KiB
JavaScript
Raw 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'},
mode: mode,
output: {
2019-01-25 22:02:29 +00:00
path: path.join(__dirname, 'dist'),
publicPath: '/'
},
module: {
2018-02-08 12:47:54 +00:00
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
query: {
presets: ['@babel/preset-env'],
plugins: ['@babel/plugin-syntax-dynamic-import']
}
}, {
test: /\.yml$/,
loader: 'json-loader!yaml-loader'
}, {
test: /\.html$/,
loader: 'html-loader'
}, {
test: /\.css$/,
loader: 'style-loader!css-loader'
}, {
test: /\.scss$/,
use: [
{loader: 'style-loader'},
{loader: 'css-loader'},
{
loader: 'sass-loader',
options: {
includePaths: [
2018-12-27 11:54:16 +00:00
path.resolve(__dirname, 'front/salix/styles')
]
}
}
]
}, {
2017-02-21 11:49:41 +00:00
test: /\.(svg|png|ttf|woff|woff2)$/,
loader: 'file-loader'
}
]
},
optimization: {
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
}
},
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']
2017-05-16 10:37:48 +00:00
})
],
devtool: 'source-map',
stats: {
modules: false,
assets: false,
2018-12-27 11:54:16 +00:00
children: false,
entrypoints: false,
colors: true
}
};
let prodConfig = {
output: {
filename: '[name].[chunkhash].js',
chunkFilename: '[id].[chunkhash].js'
},
plugins: [
new webpack.HashedModuleIdsPlugin()
],
performance: {
maxEntrypointSize: 2000000,
maxAssetSize: 2000000
}
};
let devConfig = {
output: {
filename: '[name].js',
chunkFilename: '[id].js'
},
devServer: {
host: 'localhost',
2019-01-25 22:02:29 +00:00
port: 5000,
publicPath: '/',
2019-01-25 22:02:29 +00:00
contentBase: 'dist',
quiet: false,
noInfo: false,
// hot: 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);