Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const path = require('path')
- const webpack = require('webpack')
- const src = path.resolve(__dirname, 'src')
- const options = {
- enableOptimization: false
- }
- module.exports = env => {
- const getEnvVar = v => {
- return env ? env[v] : undefined
- }
- const getEnvVarStr = v => {
- return env ? JSON.stringify(env[v]) : undefined
- }
- const base = {
- entry: {
- enumListEditor: src + '/enum-list-editor/index.js',
- projectTab: src + '/project-tab/index.js',
- pivot: src + '/pivot/index.js'
- },
- output: {
- path: path.resolve(__dirname, '../backend/src/main/resources/client'),
- filename: '[name].bundle.js'
- },
- module: {
- rules: [
- {
- test: /\.js$/,
- exclude: /node_modules/,
- loader: ['babel-loader', 'eslint-loader']
- },
- {
- test: /\.css$/,
- use: ['style-loader', 'css-loader']
- }
- ]
- },
- plugins: [
- new webpack.DefinePlugin({
- LOCAL: false
- })
- ]
- }
- const dev = {
- devServer: {
- contentBase: path.resolve(__dirname, 'html'),
- publicPath: '/',
- compress: true,
- port: 8081,
- proxy: {
- '/jira-server': {
- target: getEnvVar('server'),
- pathRewrite: { '^/jira-server': '' },
- changeOrigin: true
- }
- }
- },
- plugins: [
- new webpack.DefinePlugin({
- LOCAL: getEnvVar('local'),
- USERNAME: getEnvVarStr('user'),
- PASSWORD: getEnvVarStr('password')
- })
- ]
- }
- const prod = {
- }
- // это можно заменить react-loadable
- const optimization = {
- plugins: [
- new webpack.HashedModuleIdsPlugin()
- ],
- optimization: {
- runtimeChunk: 'single',
- splitChunks: {
- chunks: 'all',
- maxInitialRequests: Infinity,
- minSize: 0,
- cacheGroups: {
- vendor: {
- test: /[\\/]node_modules[\\/]/,
- name (module) {
- // get the name. E.g. node_modules/packageName/not/this/part.js
- // or node_modules/packageName
- const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1]
- // npm package names are URL-safe, but some servers don't like @ symbols
- return `npm.${packageName.replace('@', '')}`
- }
- }
- }
- }
- }
- }
- // собираем
- let conf = env && env.local ? { ...base, ...dev } : { ...base, ...prod }
- conf = options.enableOptimization ? { ...conf, ...optimization } : conf
- return conf
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement