-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.common-tools.js
81 lines (70 loc) · 2.48 KB
/
webpack.common-tools.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* eslint eslint-comments/no-use: off */
// const fs = require('fs')
const path = require('path')
const { EnvironmentPlugin } = require('webpack')
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
// const CleanWebpackPlugin = require('clean-webpack-plugin')
// const CompressionPlugin = require('compression-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
// const ExtractTextPlugin = require('extract-text-webpack-plugin')
// const HtmlWebpackPlugin = require('html-webpack-plugin')
const isProd = (env) => env.NODE_ENV === "production"
module.exports = {
tools: {
isProd
},
commonPlugins: {
css: (env, { filename } = { filename = '../css/app.css' }) => new MiniCssExtractPlugin({ filename }),
copyAssets: (env) => new CopyWebpackPlugin([{ from: 'static/', to: '../' }]),
},
commonModuleRules: {
js: env => ({
test: /\.(ts|js)x?$/, //pt-app, cmw-c, cmw-story
exclude: [
/node_modules/,//core, api-docs, pt-app, CN, jj, mckes, CA, phrm-ad, cmw-c
'./js/utils/test', //cmw-c
],
use: {
loader: 'babel-loader',//core, api-docs, CN, jj, mckes, CA, phrm-ad, cmw-c, cmw-story
options: {
presets: [
'@babel/react',//core
'@babel/preset-env',//core
],
plugins: ['@babel/plugin-proposal-class-properties'] //core
}
},
}),
css: env => ({
test: /\.css$/,//core, api-docs, CN, jj, mckes, CA, phrm-ad, cmw-c
use: [
{
loader: MiniCssExtractPlugin.loader,//core, api-docs, pt-app, CN, jj, mckes, CA, phrm-ad, cmw-c
options: {
hmr: !isProd(env),//pt-app
},
},
'css-loader',//core, api-docs, pt-app, CN, jj, mckes, CA, phrm-ad, cmw-c
'postcss-loader', //pt-app
]//core, api-docs
}),
file_loader: env => ({
test: /\.(eot|ttf|woff2?|otf|jpg|png|svg)(\?.*$|$)/,//core
loader: 'url-loader?limit=1000000'
})
},
config: (env = { NODE_ENV: 'development' }, options) => {
// const opts = Object.assign({}, defaultOptions, options)
const config = {}
config.mode = isProd(env) ? "production" : "development"
config.devtool = isProd(env) ? 'nosources-source-map' : 'eval-source-map'
config.entry = {
'./js/app.js': ['./js/app.js'].concat(glob.sync('./vendor/**/*.js'))
}
config.output = {
filename: 'app.js',
path: path.resolve(__dirname, '../priv/static/js')
}
return config
}
}