-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
174 lines (151 loc) · 3.55 KB
/
webpack.config.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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
const config = require('./config.js');
const webpack = require('webpack');
const path = require('path');
const autoprefixer = require('autoprefixer');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
let entry = {};
for (const e of config.entry) entry[e] = `./${config.assets}/scripts/${e}.js`;
module.exports = {
mode: 'development',
// devtool: 'cheap-module-eval-source-map', // fastest, otherwise 'inline-source-map'
// devtool: 'inline-cheap-module-source-map',
// devtool: 'inline-module-source-map',
devtool: 'cheap-module-source-map',
optimization: {
minimize: false
},
context: path.resolve(__dirname, config.src.root),
entry: entry,
output: {
path: path.resolve(__dirname, config.dist),
filename: `${config.assets}/[name].bundle.js`,
publicPath: `https://${config.host}:${config.port}/`,
chunkFilename: `${config.assets}/[name].js`
},
resolve: {
modules: [
path.resolve('./node_modules')
]
},
module: {
rules: [
{
test: /\.(jpg|png|gif|svg|mp4|mp3|ttf|eot|woff|woff2)$/,
loader: 'url-loader',
options: {
limit: 8192, // 10000
name: '[path][name].[ext]'
}
},
{
test: /\.scss$/,
// to include other dir; e.g. ./modules/banners/banner-cta/style
// include: path.resolve(__dirname, config.src),
exclude: /node_modules/,
use: [
{
loader: 'style-loader',
options: {
// to allow css before js
// this fixes things like lazyload, animations..
singleton: true
}
},
{
loader: 'css-loader',
options: {
sourceMap: true, // if disabled, prevents FOUC/FOUT, sometimes works..
}
},
{
loader: 'postcss-loader',
options: {
plugins: () => [autoprefixer({
browsers: ['last 2 versions']
})],
sourceMap: true
}
},
{
loader: 'sass-loader',
options: {
sourceMap: true
}
}
]
},
{
test: /\.js$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
]
}
]
},
// node: {
// fs: 'empty'
// },
devServer: {
disableHostCheck: true, // 3.1.14 hmr issues; quick fix
contentBase: false,
https: true,
// this or browsersync
open: true,
// openPage: `?preview_theme_id=${config.shopify.themeId}`,
openPage: `?fts=0&key=&preview_theme_id=${config.shopify.themeId}`,
proxy: {
'/': {
target: `https://${config.shopify.shopName}.myshopify.com`,
changeOrigin: true,
secure: false,
pathRewrite: {'^/' : ''}
}
},
// this or browsersync
host: config.host,
port: config.port,
compress: true, // enable gzip compression
publicPath: `https://${config.host}:${config.port}/`,
historyApiFallback: true, // history api
headers: {
"Access-Control-Allow-Origin": "*"
}
},
plugins: [
// Now the module names in console and in the source will be by name
new webpack.NamedModulesPlugin(),
new webpack.ProvidePlugin(config.dependencies),
// new webpack.optimize.UglifyJsPlugin(),
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': '"development"'
}
}),
new CopyWebpackPlugin([
{
flatten: true,
from: 'assets/fonts/**/*',
to: 'assets/'
},
{
flatten: true,
from: 'assets/images/**/*',
to: 'assets/'
},
{
from: 'theme/',
to: '../.deploy'
}
], {
// debug: true
}),
new FriendlyErrorsWebpackPlugin()
]
};