Skip to content

Commit dc35cff

Browse files
committed
reworked npm scripts
1 parent d8e2143 commit dc35cff

File tree

2 files changed

+99
-95
lines changed

2 files changed

+99
-95
lines changed

package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
"main": "ui/index.js",
66
"scripts": {
77
"dev": "npm run development",
8-
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=webpack.config.js --mode=development",
9-
"watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
8+
"development": "webpack --config=webpack.config.js --mode=development --progress --hide-modules",
9+
"watch": "npm run development -- --watch",
1010
"watch-poll": "npm run watch -- --watch-poll",
11-
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
1211
"build": "npm run production",
1312
"prod": "npm run production",
14-
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=webpack.config.js --mode=production",
13+
"production": "webpack --config=webpack.config.js --mode=production --hide-modules",
1514
"test": "echo \"Error: no test specified\" && exit 1"
1615
},
1716
"repository": {
@@ -34,7 +33,6 @@
3433
"bootstrap": "^4.1.3",
3534
"bootstrap-fileinput": "^4.4.9",
3635
"classnames": "^2.2.6",
37-
"cross-env": "^5.2.0",
3836
"css-loader": "^1.0.0",
3937
"file-loader": "^1.1.11",
4038
"jquery": "^3.3.1",

webpack.config.js

Lines changed: 96 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -13,102 +13,108 @@ const MiniCssExtractPlugin = require("mini-css-extract-plugin");
1313
* ~knoxfighter
1414
*/
1515
const FixStyleOnlyEntriesPlugin = require("webpack-fix-style-only-entries");
16-
const isProduction = process.env.NODE_ENV == 'production';
1716

18-
module.exports = {
19-
entry: {
20-
bundle: './ui/index.js',
21-
style: './ui/index.scss'
22-
},
23-
output: {
24-
filename: '[name].js',
25-
path: path.resolve(__dirname, 'app'),
26-
publicPath: ""
27-
},
28-
resolve: {
29-
alias: {
30-
Utilities: path.resolve('ui/js/')
17+
module.exports = (env, argv) => {
18+
const isProduction = argv.mode == 'production';
19+
20+
return {
21+
entry: {
22+
bundle: './ui/index.js',
23+
style: './ui/index.scss'
3124
},
32-
extensions: ['.js', '.json', '.jsx']
33-
},
34-
devtool: (isProduction) ? "none" : "source-map",
35-
module: {
36-
rules: [
37-
{
38-
test: /\.jsx?$/,
39-
exclude: /node_modules/,
40-
use: {
41-
loader: 'babel-loader'
42-
}
43-
},
44-
{
45-
test: /\.scss$/,
46-
use: [
47-
MiniCssExtractPlugin.loader,
48-
{
49-
loader: "css-loader",
50-
options: {
51-
"sourceMap": !isProduction,
52-
}
53-
},
54-
"resolve-url-loader",
55-
"sass-loader?sourceMap"
56-
]
25+
output: {
26+
filename: '[name].js',
27+
path: path.resolve(__dirname, 'app'),
28+
publicPath: ""
29+
},
30+
resolve: {
31+
alias: {
32+
Utilities: path.resolve('ui/js/')
5733
},
58-
{
59-
test: /(\.(png|jpe?g|gif)$|^((?!font).)*\.svg$)/,
60-
loaders: [
61-
{
62-
loader: "file-loader",
63-
options: {
64-
name: loader_path => {
65-
if(!/node_modules/.test(loader_path)) {
66-
return "/images/[name].[ext]?[hash]";
67-
}
34+
extensions: ['.js', '.json', '.jsx']
35+
},
36+
devtool: (isProduction) ? "none" : "source-map",
37+
module: {
38+
rules: [
39+
{
40+
test: /\.jsx?$/,
41+
exclude: /node_modules/,
42+
use: {
43+
loader: 'babel-loader'
44+
}
45+
},
46+
{
47+
test: /\.scss$/,
48+
use: [
49+
MiniCssExtractPlugin.loader,
50+
{
51+
loader: "css-loader",
52+
options: {
53+
"sourceMap": !isProduction,
54+
}
55+
},
56+
"resolve-url-loader",
57+
"sass-loader?sourceMap"
58+
]
59+
},
60+
{
61+
test: /(\.(png|jpe?g|gif)$|^((?!font).)*\.svg$)/,
62+
loaders: [
63+
{
64+
loader: "file-loader",
65+
options: {
66+
name: loader_path => {
67+
if (!/node_modules/.test(loader_path)) {
68+
return "/images/[name].[ext]?[hash]";
69+
}
6870

69-
return (
70-
"/images/vendor/" +
71-
loader_path.replace(/\\/g, "/")
72-
.replace(/((.*(node_modules))|images|image|img|assets)\//g, '') +
73-
'?[hash]'
74-
);
75-
},
71+
return (
72+
"/images/vendor/" +
73+
loader_path.replace(/\\/g, "/")
74+
.replace(/((.*(node_modules))|images|image|img|assets)\//g, '') +
75+
'?[hash]'
76+
);
77+
},
78+
}
7679
}
77-
}
78-
]
79-
},
80-
{
81-
test: /(\.(woff2?|ttf|eot|otf)$|font.*\.svg$)/,
82-
loaders: [
83-
{
84-
loader: "file-loader",
85-
options: {
86-
name: loader_path => {
87-
if (!/node_modules/.test(loader_path)) {
88-
return '/fonts/[name].[ext]?[hash]';
89-
}
80+
]
81+
},
82+
{
83+
test: /(\.(woff2?|ttf|eot|otf)$|font.*\.svg$)/,
84+
loaders: [
85+
{
86+
loader: "file-loader",
87+
options: {
88+
name: loader_path => {
89+
if (!/node_modules/.test(loader_path)) {
90+
return '/fonts/[name].[ext]?[hash]';
91+
}
9092

91-
return (
92-
'/fonts/vendor/' +
93-
loader_path
94-
.replace(/\\/g, '/')
95-
.replace(/((.*(node_modules))|fonts|font|assets)\//g, '') +
96-
'?[hash]'
97-
);
98-
},
93+
return (
94+
'/fonts/vendor/' +
95+
loader_path
96+
.replace(/\\/g, '/')
97+
.replace(/((.*(node_modules))|fonts|font|assets)\//g, '') +
98+
'?[hash]'
99+
);
100+
},
101+
}
99102
}
100-
}
101-
]
102-
}
103+
]
104+
}
105+
]
106+
},
107+
performance: {
108+
hints: false
109+
},
110+
stats: {
111+
children: false
112+
},
113+
plugins: [
114+
new FixStyleOnlyEntriesPlugin(),
115+
new MiniCssExtractPlugin({
116+
filename: "[name].css"
117+
})
103118
]
104-
},
105-
performance: {
106-
hints: false
107-
},
108-
plugins: [
109-
new FixStyleOnlyEntriesPlugin(),
110-
new MiniCssExtractPlugin({
111-
filename: "[name].css"
112-
})
113-
]
119+
}
114120
}

0 commit comments

Comments
 (0)