babel-loader 6.3.0 → 6.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/README.md +25 -6
- package/lib/index.js +58 -12
- package/package.json +5 -1
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,39 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v6.4.0
|
4
|
+
|
5
|
+
### 🚀 New Feature
|
6
|
+
|
7
|
+
- added metadata passing from babel to webpack, which is currently used by react-intl (#398) @Ognian
|
8
|
+
|
9
|
+
## v6.3.2
|
10
|
+
|
11
|
+
### 😢 Regression
|
12
|
+
|
13
|
+
- `forceEnv` was interfering with regular environment handling
|
14
|
+
|
15
|
+
## v6.3.1
|
16
|
+
|
17
|
+
### 🐛 Bug Fix
|
18
|
+
|
19
|
+
- The new `forceEnv` options wasn't working as expected (#379) @chrisvasz
|
20
|
+
|
21
|
+
## v6.3.0
|
22
|
+
|
23
|
+
### 🚀 New Feature
|
24
|
+
|
25
|
+
- Add new config option `forceEnv` (#368) @moimael
|
26
|
+
|
27
|
+
Allow to override BABEL_ENV/NODE_ENV at loader-level. Useful for isomorphic applications which have separate babel config for client and server.
|
28
|
+
|
29
|
+
### 🐛 Bug Fix
|
30
|
+
|
31
|
+
- Update loader-utils dependency to ^0.2.16 to fix compatibility with webpack 2 (#371) @leonaves
|
32
|
+
|
33
|
+
### 💅 Polish
|
34
|
+
|
35
|
+
- Improve FS caching to do less sync calls which improves performance slightly (#375) @akx
|
36
|
+
|
3
37
|
## v6.2.10
|
4
38
|
|
5
39
|
Support for webpack 2.2-rc has been added in this release
|
package/README.md
CHANGED
@@ -12,13 +12,13 @@
|
|
12
12
|
## Installation
|
13
13
|
|
14
14
|
```bash
|
15
|
-
npm install babel-loader babel-core babel-preset-
|
15
|
+
npm install babel-loader babel-core babel-preset-env webpack --save-dev
|
16
16
|
```
|
17
17
|
|
18
18
|
or
|
19
19
|
|
20
20
|
```bash
|
21
|
-
yarn add babel-loader babel-core babel-preset-
|
21
|
+
yarn add babel-loader babel-core babel-preset-env webpack --dev
|
22
22
|
```
|
23
23
|
|
24
24
|
__Note:__ [npm](https://npmjs.com) deprecated [auto-installing of peerDependencies](https://github.com/npm/npm/issues/6565) since npm@3, so required peer dependencies like babel-core and webpack must be listed explicitly in your `package.json`.
|
@@ -39,7 +39,7 @@ module: {
|
|
39
39
|
exclude: /(node_modules|bower_components)/,
|
40
40
|
loader: 'babel-loader',
|
41
41
|
query: {
|
42
|
-
presets: ['
|
42
|
+
presets: ['env']
|
43
43
|
}
|
44
44
|
}
|
45
45
|
]
|
@@ -58,7 +58,7 @@ module: {
|
|
58
58
|
{
|
59
59
|
test: /\.js$/,
|
60
60
|
exclude: /(node_modules|bower_components)/,
|
61
|
-
loader: 'babel-loader?presets[]=
|
61
|
+
loader: 'babel-loader?presets[]=env'
|
62
62
|
}
|
63
63
|
]
|
64
64
|
}
|
@@ -74,13 +74,32 @@ module: {
|
|
74
74
|
exclude: /(node_modules|bower_components)/,
|
75
75
|
loader: 'babel-loader',
|
76
76
|
query: {
|
77
|
-
presets: ['
|
77
|
+
presets: ['env']
|
78
78
|
}
|
79
79
|
}
|
80
80
|
]
|
81
81
|
}
|
82
82
|
```
|
83
83
|
|
84
|
+
or by using global options:
|
85
|
+
|
86
|
+
> Be aware that this only works in webpack 1 and not in version 2.
|
87
|
+
|
88
|
+
```javascript
|
89
|
+
module: {
|
90
|
+
loaders: [
|
91
|
+
{
|
92
|
+
test: /\.js$/,
|
93
|
+
exclude: /(node_modules|bower_components)/,
|
94
|
+
loader: 'babel-loader'
|
95
|
+
}
|
96
|
+
]
|
97
|
+
},
|
98
|
+
babel: {
|
99
|
+
presets: ['es2015']
|
100
|
+
}
|
101
|
+
```
|
102
|
+
|
84
103
|
This loader also supports the following loader-specific option:
|
85
104
|
|
86
105
|
* `cacheDirectory`: Default `false`. When set, the given directory will be used to cache the results of the loader. Future webpack builds will attempt to read from the cache to avoid needing to run the potentially expensive Babel recompilation process on each run. If the value is blank (`loader: 'babel-loader?cacheDirectory'`) or `true` (`loader: babel-loader?cacheDirectory=true`) the loader will use the default cache directory in `node_modules/.cache/babel-loader` or fallback to the default OS temporary file directory if no `node_modules` folder could be found in any root directory.
|
@@ -129,7 +148,7 @@ loaders: [
|
|
129
148
|
exclude: /(node_modules|bower_components)/,
|
130
149
|
loader: 'babel-loader',
|
131
150
|
query: {
|
132
|
-
presets: ['
|
151
|
+
presets: ['env'],
|
133
152
|
plugins: ['transform-runtime']
|
134
153
|
}
|
135
154
|
}
|
package/lib/index.js
CHANGED
@@ -31,10 +31,21 @@ var formatMessage = function formatMessage(name, message, codeFrame) {
|
|
31
31
|
};
|
32
32
|
|
33
33
|
var transpile = function transpile(source, options) {
|
34
|
+
var forceEnv = options.forceEnv;
|
35
|
+
var tmpEnv = void 0;
|
36
|
+
|
37
|
+
delete options.forceEnv;
|
38
|
+
|
39
|
+
if (forceEnv) {
|
40
|
+
tmpEnv = process.env.BABEL_ENV;
|
41
|
+
process.env.BABEL_ENV = forceEnv;
|
42
|
+
}
|
43
|
+
|
34
44
|
var result = void 0;
|
35
45
|
try {
|
36
46
|
result = babel.transform(source, options);
|
37
47
|
} catch (error) {
|
48
|
+
if (forceEnv) restoreBabelEnv(tmpEnv);
|
38
49
|
if (error.message && error.codeFrame) {
|
39
50
|
var message = error.message;
|
40
51
|
var name = void 0;
|
@@ -54,19 +65,37 @@ var transpile = function transpile(source, options) {
|
|
54
65
|
}
|
55
66
|
var code = result.code;
|
56
67
|
var map = result.map;
|
68
|
+
var metadata = result.metadata;
|
57
69
|
|
58
70
|
if (map && (!map.sourcesContent || !map.sourcesContent.length)) {
|
59
71
|
map.sourcesContent = [source];
|
60
72
|
}
|
61
73
|
|
74
|
+
if (forceEnv) restoreBabelEnv(tmpEnv);
|
75
|
+
|
62
76
|
return {
|
63
77
|
code: code,
|
64
|
-
map: map
|
78
|
+
map: map,
|
79
|
+
metadata: metadata
|
65
80
|
};
|
66
81
|
};
|
67
82
|
|
83
|
+
function restoreBabelEnv(prevValue) {
|
84
|
+
if (prevValue === undefined) {
|
85
|
+
delete process.env.BABEL_ENV;
|
86
|
+
} else {
|
87
|
+
process.env.BABEL_ENV = prevValue;
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
function passMetadata(s, context, metadata) {
|
92
|
+
if (context[s]) {
|
93
|
+
context[s](metadata);
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
68
97
|
module.exports = function (source, inputSourceMap) {
|
69
|
-
var
|
98
|
+
var _this = this;
|
70
99
|
|
71
100
|
var webpackRemainingChain = loaderUtils.getRemainingRequest(this).split("!");
|
72
101
|
var filename = webpackRemainingChain[webpackRemainingChain.length - 1];
|
@@ -75,6 +104,7 @@ module.exports = function (source, inputSourceMap) {
|
|
75
104
|
var loaderOptions = loaderUtils.parseQuery(this.query);
|
76
105
|
var userOptions = assign({}, globalOptions, loaderOptions);
|
77
106
|
var defaultOptions = {
|
107
|
+
metadataSubscribers: [],
|
78
108
|
inputSourceMap: inputSourceMap,
|
79
109
|
sourceRoot: process.cwd(),
|
80
110
|
filename: filename,
|
@@ -82,12 +112,10 @@ module.exports = function (source, inputSourceMap) {
|
|
82
112
|
"babel-loader": pkg.version,
|
83
113
|
"babel-core": babel.version,
|
84
114
|
babelrc: exists(userOptions.babelrc) ? read(userOptions.babelrc) : resolveRc(path.dirname(filename)),
|
85
|
-
env: userOptions.forceEnv || process.env.BABEL_ENV || process.env.NODE_ENV
|
115
|
+
env: userOptions.forceEnv || process.env.BABEL_ENV || process.env.NODE_ENV || "development"
|
86
116
|
})
|
87
117
|
};
|
88
118
|
|
89
|
-
delete userOptions.forceEnv;
|
90
|
-
|
91
119
|
var options = assign({}, defaultOptions, userOptions);
|
92
120
|
|
93
121
|
if (userOptions.sourceMap === undefined) {
|
@@ -100,9 +128,11 @@ module.exports = function (source, inputSourceMap) {
|
|
100
128
|
|
101
129
|
var cacheDirectory = options.cacheDirectory;
|
102
130
|
var cacheIdentifier = options.cacheIdentifier;
|
131
|
+
var metadataSubscribers = options.metadataSubscribers;
|
103
132
|
|
104
133
|
delete options.cacheDirectory;
|
105
134
|
delete options.cacheIdentifier;
|
135
|
+
delete options.metadataSubscribers;
|
106
136
|
|
107
137
|
this.cacheable();
|
108
138
|
|
@@ -114,14 +144,30 @@ module.exports = function (source, inputSourceMap) {
|
|
114
144
|
source: source,
|
115
145
|
options: options,
|
116
146
|
transform: transpile
|
117
|
-
}, function (err
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
147
|
+
}, function (err) {
|
148
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
149
|
+
code = _ref.code,
|
150
|
+
map = _ref.map,
|
151
|
+
metadata = _ref.metadata;
|
152
|
+
|
153
|
+
if (err) return callback(err);
|
154
|
+
|
155
|
+
metadataSubscribers.forEach(function (s) {
|
156
|
+
return passMetadata(s, _this, metadata);
|
157
|
+
});
|
158
|
+
|
159
|
+
return callback(null, code, map);
|
122
160
|
});
|
123
161
|
}
|
124
162
|
|
125
|
-
|
126
|
-
|
163
|
+
var _transpile = transpile(source, options),
|
164
|
+
code = _transpile.code,
|
165
|
+
map = _transpile.map,
|
166
|
+
metadata = _transpile.metadata;
|
167
|
+
|
168
|
+
metadataSubscribers.forEach(function (s) {
|
169
|
+
return passMetadata(s, _this, metadata);
|
170
|
+
});
|
171
|
+
|
172
|
+
this.callback(null, code, map);
|
127
173
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "babel-loader",
|
3
|
-
"version": "6.
|
3
|
+
"version": "6.4.1",
|
4
4
|
"description": "babel module loader for webpack",
|
5
5
|
"files": [
|
6
6
|
"lib"
|
@@ -22,6 +22,7 @@
|
|
22
22
|
"babel-core": "^6.0.0",
|
23
23
|
"babel-eslint": "^7.1.0",
|
24
24
|
"babel-plugin-istanbul": "^3.0.0",
|
25
|
+
"babel-plugin-react-intl": "^2.1.3",
|
25
26
|
"babel-preset-es2015": "^6.0.0",
|
26
27
|
"babel-preset-latest": "^6.16.0",
|
27
28
|
"babel-register": "^6.18.0",
|
@@ -31,6 +32,9 @@
|
|
31
32
|
"eslint-config-babel": "^6.0.0",
|
32
33
|
"eslint-plugin-flowtype": "^2.25.0",
|
33
34
|
"nyc": "^10.0.0",
|
35
|
+
"react": "^15.1.0",
|
36
|
+
"react-intl": "^2.1.2",
|
37
|
+
"react-intl-webpack-plugin": "^0.0.3",
|
34
38
|
"rimraf": "^2.4.3",
|
35
39
|
"webpack": "^2.2.0-rc"
|
36
40
|
},
|