Skip to content

Commit

Permalink
Using ES6 on webpack.config and transpiling it with babel-core
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenspgcavalcante committed Jan 27, 2017
1 parent b306b66 commit ef85bee
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
],
"main": "dist/leaflet-ant-path.js",
"scripts": {
"build": "NODE_ENV=production webpack --config webpack.config.js",
"build": "NODE_ENV=production webpack --config webpack.transpiler.js --colors --profile --progress",
"test": "karma start --log-level debug --single-run",
"start": "NODE_ENV=development webpack-dev-server -d --inline --host 0.0.0.0",
"start": "NODE_ENV=development webpack-dev-server --config webpack.transpiler.js -d --cache --inline --host 0.0.0.0",
"codacy": "cat coverage/lcov/lcov.info | codacy-coverage",
"prepublish": "npm run build"
},
Expand Down
25 changes: 12 additions & 13 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
var path = require("path");
var webpack = require("webpack");
var merge = require("merge");
var loaders = require("./webpack/loaders");
var development = require("./webpack/development");
var production = require("./webpack/production");
import path from "path";
import merge from "merge";
import loaders from "./webpack/loaders";
import development from "./webpack/development";
import production from "./webpack/production";
const {NODE_ENV} = process.env;


var configuration = {
let configuration = {
output: {
path: path.resolve("./dist"),
filename: "[name].js",
Expand All @@ -19,23 +18,23 @@ var configuration = {
hot: true
},
module: {
loaders: loaders
loaders
}
};

switch (process.env.NODE_ENV) {
switch (NODE_ENV) {
case "production":
console.info("Using production configurations");
configuration = merge(configuration, production);
break;

case "development":
console.info("Using development configurations");
configuration = merge(configuration, development);
break;

default:
throw new Error("Please define your NODE_ENV to development or production!");
}

module.exports = configuration;
console.info(`Using ${NODE_ENV} configurations`);

export default configuration;
10 changes: 10 additions & 0 deletions webpack.transpiler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* This code transpiles the webpack config from ES6 to ES5
* While Node not supports 100% ES6 keep using this file as config file for webpack!
*/

var babel = require("babel-core");
var path = require("path");
var transpiled = babel.transformFileSync(path.resolve("./webpack.config.js"));

module.exports = eval(transpiled.code);
2 changes: 1 addition & 1 deletion webpack/loaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ module.exports = [
{test: /\.(woff2?|svg)$/, loader: require.resolve("url-loader")},
{test: /\.(ttf|eot|png|jpge?g)$/, loader: require.resolve("file-loader")},
{test: /\.json$/, exclude: "/node_modules/", loader: require.resolve("json-loader")}
]
];

0 comments on commit ef85bee

Please sign in to comment.