forked from codex-team/editor.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
211 lines (188 loc) · 5.04 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/**
* Webpack configuration
*
* @author Codex Team
* @copyright Khaydarov Murod
*/
'use strict';
var pkg = require('./package.json');
var path = require('path');
/**
* Environment
* @type {any}
*/
const NODE_ENV = process.env.NODE_ENV || 'development';
const VERSION = process.env.VERSION || pkg.version;
/**
* Plugins for bundle
* @type {webpack}
*/
var webpack = require('webpack');
/**
* File system
*/
var fs = require('fs');
/**
* Available CodeX Editor modules placed in components/modules folder
* They will required automatically.
* Folders and files starting with '_' will be skipped
* @type {Array}
*/
var editorModules = fs.readdirSync('./src/components/modules').filter( name => /.(j|t)s$/.test(name) && name.substring(0,1) !== '_' );
editorModules.forEach( name => {
console.log('Require modules/' + name);
});
/**
* Options for the Babel
*/
var babelLoader = {
loader: 'babel-loader',
options: {
cacheDirectory: true,
plugins: [
/**
* Dont need to use «.default» after «export default Class Ui {}»
* @see {@link https://github.com/59naga/babel-plugin-add-module-exports}
*/
// 'add-module-exports',
/**
* Babel transforms some awesome ES6 features to ES5 with extra code, such as Class, JSX.
* This plugin makes all generated extra codes to one module which significantly reduces the bundle code size.
*
* {@link https://github.com/brianZeng/babel-plugin-transform-helper}
* @since 11 dec 2017 - removed due to plugin does not supports class inheritance
*/
// ['babel-plugin-transform-helper', {
// helperFilename:'build/__tmp_babel_helpers.js'
// }],
// 'class-display-name',
]
}
};
module.exports = {
entry: {
'codex-editor': [ './src/codex' ]
},
output: {
path: path.resolve(__dirname, 'build'),
filename: '[name].js',
library: [ 'CodexEditor' ],
libraryTarget: 'umd'
},
watch: true,
watchOptions: {
aggregateTimeout: 50
},
devtool: NODE_ENV == 'development' ? 'source-map' : null,
/**
* Tell webpack what directories should be searched when resolving modules.
*/
resolve : {
// fallback: path.join(__dirname, 'node_modules'),
modules : [ path.join(__dirname, "src"), "node_modules"],
extensions: ['.js', '.ts'],
alias: {
'utils': path.resolve(__dirname + '/src/components/', './utils'),
'dom': path.resolve(__dirname + '/src/components/', './dom'),
}
},
//
// resolveLoader : {
// modules: [ path.resolve(__dirname, "src"), "node_modules" ],
// moduleTemplates: ['*-webpack-loader', '*-web-loader', '*-loader', '*'],
// extensions: ['.js']
// },
plugins: [
/** Pass variables into modules */
new webpack.DefinePlugin({
NODE_ENV: JSON.stringify(NODE_ENV),
VERSION: JSON.stringify(VERSION),
editorModules: JSON.stringify(editorModules)
}),
/**
* Setting up a dynamic requires that we use to autoload Editor Modules from 'components/modules' dir
* {@link https://webpack.js.org/plugins/context-replacement-plugin/}
*/
new webpack.ContextReplacementPlugin(
/src\/components\/modules/,
false, // newContentRecursive=false because we dont need to include folders
new RegExp(
'[^_]' + // dont match names started with '_'
`(${editorModules.join('|')})` + // module names pattern: (events.js|ui.js|...)
'$' // at the end of path
)
),
/**
* Automatically load global visible modules
* instead of having to import/require them everywhere.
*/
new webpack.ProvidePlugin({
'_': 'utils',
'$': 'dom',
'Module': './../__module.ts',
}),
/** Минифицируем CSS и JS */
// new webpack.optimize.UglifyJsPlugin({
/** Disable warning messages. Cant disable uglify for 3rd party libs such as html-janitor */
// compress: {
// warnings: false
// }
// }),
/** Block biuld if errors found */
// new webpack.NoErrorsPlugin(),
],
module : {
rules : [
{
test: /\.ts$/,
use: [
babelLoader,
{
loader: 'ts-loader'
},
{
loader: 'tslint-loader',
}
]
},
{
test : /\.js$/,
use: [
babelLoader,
{
loader: 'eslint-loader?fix=true&esModules=true',
}
],
exclude: [
/(node_modules|build)/, // dont need to look in '/build' to prevent analyse __tmp_babel_helper.js
/src[\\\/]components[\\\/]tools/
]
},
{
test: /\.css$/,
exclude: /node_modules/,
use: [
{
loader: 'css-loader',
options: {
// minimize: 1,
importLoaders: 1
}
},
'postcss-loader'
]
},
{
test: /\.(svg)$/,
use: [
{
loader: 'raw-loader',
}
]
}
]
},
optimization: {
minimize: true
},
};