Skip to content

Commit 0de4958

Browse files
committed
Merge pull request kriasoft#493 from frenzzy/babel-node-5
Use babel-preset-node5 for npm scripts
2 parents 738a0dd + 2520eb1 commit 0de4958

File tree

4 files changed

+114
-60
lines changed

4 files changed

+114
-60
lines changed

.babelrc

Lines changed: 0 additions & 10 deletions
This file was deleted.

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"babel-plugin-react-transform": "^2.0.2",
4848
"babel-plugin-transform-runtime": "^6.6.0",
4949
"babel-preset-es2015": "^6.6.0",
50+
"babel-preset-node5": "^10.8.0",
5051
"babel-preset-react": "^6.5.0",
5152
"babel-preset-stage-0": "^6.5.0",
5253
"browser-sync": "^2.11.1",
@@ -87,6 +88,13 @@
8788
"webpack-hot-middleware": "^2.10.0",
8889
"webpack-middleware": "^1.5.1"
8990
},
91+
"babel": {
92+
"presets": [
93+
"react",
94+
"node5",
95+
"stage-0"
96+
]
97+
},
9098
"jest": {
9199
"rootDir": "./src",
92100
"testPathDirs": [

tools/start.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,12 @@ async function start() {
4545
.loaders
4646
.filter(x => x.loader === 'babel-loader')
4747
.forEach(x => (x.query = { // eslint-disable-line no-param-reassign
48+
...x.query,
49+
4850
// Wraps all React components into arbitrary transforms
4951
// https://github.com/gaearon/babel-plugin-react-transform
5052
plugins: [
53+
...(x.query ? x.query.plugins : []),
5154
['react-transform', {
5255
transforms: [
5356
{

tools/webpack.config.js

Lines changed: 103 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -35,44 +35,39 @@ const GLOBALS = {
3535
// -----------------------------------------------------------------------------
3636

3737
const config = {
38+
context: path.join(__dirname, '../src'),
39+
3840
output: {
3941
publicPath: '/',
4042
sourcePrefix: ' ',
4143
},
4244

43-
cache: DEBUG,
44-
debug: DEBUG,
45-
46-
stats: {
47-
colors: true,
48-
reasons: DEBUG,
49-
hash: VERBOSE,
50-
version: VERBOSE,
51-
timings: true,
52-
chunks: VERBOSE,
53-
chunkModules: VERBOSE,
54-
cached: VERBOSE,
55-
cachedAssets: VERBOSE,
56-
},
57-
58-
plugins: [
59-
new webpack.optimize.OccurenceOrderPlugin(),
60-
],
61-
62-
resolve: {
63-
extensions: ['', '.webpack.js', '.web.js', '.js', '.jsx', '.json'],
64-
},
65-
6645
module: {
6746
loaders: [
6847
{
6948
test: /\.jsx?$/,
49+
loader: 'babel-loader',
7050
include: [
7151
path.resolve(__dirname, '../node_modules/react-routing/src'),
7252
path.resolve(__dirname, '../src'),
7353
],
74-
loader: 'babel-loader',
75-
}, {
54+
query: {
55+
// https://github.com/babel/babel-loader#options
56+
cacheDirectory: DEBUG,
57+
58+
// https://babeljs.io/docs/usage/options/
59+
babelrc: false,
60+
presets: [
61+
'react',
62+
'es2015',
63+
'stage-0',
64+
],
65+
plugins: [
66+
'transform-runtime',
67+
],
68+
},
69+
},
70+
{
7671
test: /\.scss$/,
7772
loaders: [
7873
'isomorphic-style-loader',
@@ -88,26 +83,52 @@ const config = {
8883
})}`,
8984
'postcss-loader?parser=postcss-scss',
9085
],
91-
}, {
86+
},
87+
{
9288
test: /\.json$/,
9389
loader: 'json-loader',
94-
}, {
90+
},
91+
{
9592
test: /\.txt$/,
9693
loader: 'raw-loader',
97-
}, {
94+
},
95+
{
9896
test: /\.(png|jpg|jpeg|gif|svg|woff|woff2)$/,
9997
loader: 'url-loader?limit=10000',
100-
}, {
98+
},
99+
{
101100
test: /\.(eot|ttf|wav|mp3)$/,
102101
loader: 'file-loader',
103-
}, {
102+
},
103+
{
104104
test: /\.jade$/,
105105
loader: 'jade-loader',
106106
},
107107
],
108108
},
109109

110-
postcss: function plugins(bundler) {
110+
resolve: {
111+
root: path.join(__dirname, '../src'),
112+
modulesDirectories: ['node_modules'],
113+
extensions: ['', '.webpack.js', '.web.js', '.js', '.jsx', '.json'],
114+
},
115+
116+
cache: DEBUG,
117+
debug: DEBUG,
118+
119+
stats: {
120+
colors: true,
121+
reasons: DEBUG,
122+
hash: VERBOSE,
123+
version: VERBOSE,
124+
timings: true,
125+
chunks: VERBOSE,
126+
chunkModules: VERBOSE,
127+
cached: VERBOSE,
128+
cachedAssets: VERBOSE,
129+
},
130+
131+
postcss(bundler) {
111132
return [
112133
require('postcss-import')({ addDependencyTo: bundler }),
113134
require('precss')(),
@@ -121,51 +142,75 @@ const config = {
121142
// -----------------------------------------------------------------------------
122143

123144
const clientConfig = extend(true, {}, config, {
124-
entry: './src/client.js',
145+
entry: './client.js',
146+
125147
output: {
126148
path: path.join(__dirname, '../build/public'),
127149
filename: DEBUG ? '[name].js?[hash]' : '[name].[hash].js',
150+
chunkFilename: DEBUG ? '[name].[id].js?[hash]' : '[name].[id].[hash].js',
128151
},
129152

130-
// Choose a developer tool to enhance debugging
131-
// http://webpack.github.io/docs/configuration.html#devtool
132-
devtool: DEBUG ? 'cheap-module-eval-source-map' : false,
153+
target: 'web',
154+
133155
plugins: [
134-
...config.plugins,
156+
157+
// Define free variables
158+
// https://webpack.github.io/docs/list-of-plugins.html#defineplugin
135159
new webpack.DefinePlugin({ ...GLOBALS, 'process.env.BROWSER': true }),
160+
161+
// Emit a file with assets paths
162+
// https://github.com/sporto/assets-webpack-plugin#options
136163
new AssetsPlugin({
137164
path: path.join(__dirname, '../build'),
138165
filename: 'assets.js',
139166
processOutput: x => `module.exports = ${JSON.stringify(x)};`,
140167
}),
141-
...(!DEBUG ? [
168+
169+
...(DEBUG ? [] : [
170+
171+
// Search for equal or similar files and deduplicate them in the output
172+
// https://webpack.github.io/docs/list-of-plugins.html#dedupeplugin
142173
new webpack.optimize.DedupePlugin(),
174+
175+
// Assign the module and chunk ids by occurrence count
176+
// https://webpack.github.io/docs/list-of-plugins.html#occurrenceorderplugin
177+
new webpack.optimize.OccurenceOrderPlugin(true),
178+
179+
// Minimize all JavaScript output of chunks
180+
// https://github.com/mishoo/UglifyJS2#compressor-options
143181
new webpack.optimize.UglifyJsPlugin({
144182
compress: {
145-
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
146-
screw_ie8: true,
147-
148-
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
183+
screw_ie8: true, // jscs:ignore requireCamelCaseOrUpperCaseIdentifiers
149184
warnings: VERBOSE,
150185
},
151186
}),
187+
188+
// A plugin for a more aggressive chunk merging strategy
189+
// https://webpack.github.io/docs/list-of-plugins.html#aggressivemergingplugin
152190
new webpack.optimize.AggressiveMergingPlugin(),
153-
] : []),
191+
]),
154192
],
193+
194+
// Choose a developer tool to enhance debugging
195+
// http://webpack.github.io/docs/configuration.html#devtool
196+
devtool: DEBUG ? 'cheap-module-eval-source-map' : false,
155197
});
156198

157199
//
158200
// Configuration for the server-side bundle (server.js)
159201
// -----------------------------------------------------------------------------
160202

161203
const serverConfig = extend(true, {}, config, {
162-
entry: './src/server.js',
204+
entry: './server.js',
205+
163206
output: {
164-
path: './build',
207+
path: path.join(__dirname, '../build'),
165208
filename: 'server.js',
166209
libraryTarget: 'commonjs2',
167210
},
211+
168212
target: 'node',
213+
169214
externals: [
170215
/^\.\/assets$/,
171216
function filter(context, request, cb) {
@@ -176,6 +221,19 @@ const serverConfig = extend(true, {}, config, {
176221
cb(null, Boolean(isExternal));
177222
},
178223
],
224+
225+
plugins: [
226+
227+
// Define free variables
228+
// https://webpack.github.io/docs/list-of-plugins.html#defineplugin
229+
new webpack.DefinePlugin({ ...GLOBALS, 'process.env.BROWSER': false }),
230+
231+
// Adds a banner to the top of each generated chunk
232+
// https://webpack.github.io/docs/list-of-plugins.html#bannerplugin
233+
new webpack.BannerPlugin('require("source-map-support").install();',
234+
{ raw: true, entryOnly: false }),
235+
],
236+
179237
node: {
180238
console: false,
181239
global: false,
@@ -184,13 +242,8 @@ const serverConfig = extend(true, {}, config, {
184242
__filename: false,
185243
__dirname: false,
186244
},
245+
187246
devtool: 'source-map',
188-
plugins: [
189-
...config.plugins,
190-
new webpack.DefinePlugin({ ...GLOBALS, 'process.env.BROWSER': false }),
191-
new webpack.BannerPlugin('require("source-map-support").install();',
192-
{ raw: true, entryOnly: false }),
193-
],
194247
});
195248

196249
export default [clientConfig, serverConfig];

0 commit comments

Comments
 (0)