-
Notifications
You must be signed in to change notification settings - Fork 8
/
webpack.config.js
129 lines (121 loc) · 3.61 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
const webpack = require('webpack');
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
/* este diretório é onde será gerada automaticamente toda estrutura da extensão */
const outputPath = path.resolve(__dirname, 'dist/expanded');
module.exports = {
mode:
process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'production'
? process.env.NODE_ENV
: process.env.NODE_ENV === 'test'
? 'none'
: 'development',
entry: {
/* entry points da app */
process_list: './src/js/entries/process_list',
process_content: './src/js/entries/process_content',
/* outros scripts */
common: './src/js/common.js',
service_worker: './src/js/service_worker.js',
options: './src/js/options.js',
},
output: {
path: outputPath,
filename: ({ chunk }) => {
if (['options'].includes(chunk.name)) {
return 'html/[name].js';
} else {
return 'js/[name].js';
}
},
},
resolve: {
alias: {
model: path.resolve(__dirname, 'src/js/model'),
view: path.resolve(__dirname, 'src/js/view'),
controller: path.resolve(__dirname, 'src/js/controller'),
api: path.resolve(__dirname, 'src/js/api'),
actions: path.resolve(__dirname, 'src/js/actions'),
utils: path.resolve(__dirname, 'src/js/utils'),
tests: path.resolve(__dirname, 'src/__tests__'),
css: path.resolve(__dirname, 'src/css'),
},
},
module: {
rules: [
/* estilos neste path serão exportados para um .css */
{
test: /\.scss$/,
include: [path.resolve(__dirname, 'src/css')],
use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader', 'sass-loader'],
},
/* estilos dos componentes não serão exportados para arquivo */
{
test: /\.scss$/,
include: [path.resolve(__dirname, 'src/js')],
use: [
'style-loader',
{
loader: 'css-loader',
options: {
importLoaders: 1,
modules: true,
},
},
'postcss-loader',
'sass-loader',
],
},
/* estilos dos componentes importados do node_modules */
{
test: /\.(scss|css)$/,
include: [path.resolve(__dirname, 'node_modules')],
use: ['style-loader', 'css-loader?importLoaders=1', 'sass-loader'],
},
/* transforma os js */
{
test: /\.js$/,
exclude: /(node_modules)/,
use: {
loader: 'babel-loader',
},
},
/* carrega as imagens em DataURL*/
{
test: /\.(png|jpg|gif|svg)$/,
use: [
{
loader: 'url-loader',
options: { limit: 8192, fallback: 'file-loader' },
},
],
},
],
},
devtool: 'cheap-module-source-map',
plugins: [
new MiniCssExtractPlugin({
filename: ({ chunk }) => {
if (['options'].includes(chunk.name)) {
return 'html/[name].css';
} else {
return 'css/[name].css';
}
},
}),
new CleanWebpackPlugin(),
new CopyWebpackPlugin({
patterns: [
{ from: 'src/manifest.json', to: outputPath + '/' },
{ from: 'src/icons', to: outputPath + '/icons' },
{ from: 'src/html', to: outputPath + '/html' },
],
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
'process.env.MOCKED_API': JSON.stringify('false'),
}),
],
};