-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack-node.config.js
More file actions
150 lines (145 loc) · 4.12 KB
/
webpack-node.config.js
File metadata and controls
150 lines (145 loc) · 4.12 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// webpack.config.js
const path = require('path');
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
const MinifyPlugin = require('babel-minify-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const StyleLintPlugin = require('stylelint-webpack-plugin');
const webpack = require('webpack');
const config = {
mode: 'development',
entry: {
tools: './tools/watch.js'
},
devtool: 'source-map',
node: {
fs: 'empty'
},
target: 'node',
// devtool: 'cheap-module-eval-source-map', // supposed to be fastest but doesnt work
output: {
// If within normal JS framework environment,
// use this to autogenerate hash
// filename: '[name].[chunkhash].js'
filename: '[name].js',
// publicPath: './wpTheme',
path: path.resolve(__dirname, 'public')
},
watchOptions: {
// ignored: ['./test/'] // Let Express handle rebuilding
},
module: {
rules: [
{
test: /\.(woff|woff2|eot|ttf|svg|png)$/,
loader: 'url-loader',
options: {
limit: 8192,
// name: '[name].[ext]',
name: '[name]-[hash].[ext]',
publicPath: '../assets/',
outputPath: './dist/assets/'
// emitFile: false
}
// inline base64 URLs for <=8k fonts/svgs, direct URLs for the rest
// outputPath is relative to the module output path
// publicPath is relative to the minified CSS ouptut (or file) that calls it
// emitfile to be false if there is no need to recreate a file
// by specifying name without the [hash], can output without using the auto hash system of webpack
// otherwise it can be bundled together with auto hashing
},
{
test:/\.(s*)css$/,
use: [
{
loader: MiniCssExtractPlugin.loader
},
// This is the fallback if don't want to extract the CSS
// {
// loader: "style-loader",
// },
{
loader: 'css-loader',
options: {
sourceMap: true
// modules: true,
// localIdentName: "[local]___[hash:base64:5]"
}
},
{
loader: 'postcss-loader',
options: {
plugins: () => [require('autoprefixer')]
}
},
{
loader: 'sass-loader',
options: {
sourceMap: true
}
}
]
}
]
}
};
module.exports = (env, argv) => {
// console.log(argv.mode); // outputs development
if (argv.mode === 'development') {
config.module.rules.push({
test: /\.js$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
},
{
loader: 'eslint-loader',
options: {
fix: true
}
}
]
});
config.plugins = [
new webpack.IgnorePlugin(/jsdom$/),
new MiniCssExtractPlugin({
filename: '[name].css'
}),
new StyleLintPlugin({
configFile: '.stylelintrc'
}),
// new BrowserSyncPlugin(
// {
// host: 'localhost',
// port: 3000,
// proxy: 'http://localhost:1234/'
// }
// )
];
}
if (argv.mode === 'production') {
config.mode = 'production';
config.devtool = false,
config.optimization = {
minimizer: [
new OptimizeCSSAssetsPlugin({})
]
};
config.plugins = [
new webpack.IgnorePlugin(/jsdom$/),
new MiniCssExtractPlugin({
// If within normal JS framework environment,
// use this to autogenerate hash
// filename: 'style.[contenthash].css',
filename: '[name].css'
}),
new OptimizeCSSAssetsPlugin({}),
new MinifyPlugin()
];
}
return config;
};