From 9aea569749cba051f891d3b5d48f93066be8ece6 Mon Sep 17 00:00:00 2001 From: Sebastian Werner Date: Mon, 26 Jun 2017 07:47:24 +0200 Subject: [PATCH] Switched to root import plugin replacing module-resolver plugin. --- package-lock.json | 5 +++++ package.json | 1 + src/index.js | 14 ++++++++++---- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index a035096..f32bbff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -543,6 +543,11 @@ "resolved": "https://registry.npmjs.org/babel-plugin-react-intl/-/babel-plugin-react-intl-2.3.1.tgz", "integrity": "sha1-PUORLoJNoAXgjo6COdW6eEN0uwA=" }, + "babel-plugin-root-import": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/babel-plugin-root-import/-/babel-plugin-root-import-5.1.0.tgz", + "integrity": "sha1-gOoc1ZRbRjpeP34gSmlHjFc+Mow=" + }, "babel-plugin-syntax-async-functions": { "version": "6.13.0", "resolved": "https://registry.npmjs.org/babel-plugin-syntax-async-functions/-/babel-plugin-syntax-async-functions-6.13.0.tgz", diff --git a/package.json b/package.json index 54bc6cf..987b719 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "babel-plugin-fast-async": "^6.1.2", "babel-plugin-lodash": "^3.2.11", "babel-plugin-react-intl": "^2.3.1", + "babel-plugin-root-import": "^5.1.0", "babel-plugin-syntax-dynamic-import": "^6.18.0", "babel-plugin-transform-class-properties": "^6.24.1", "babel-plugin-transform-object-rest-spread": "^6.23.0", diff --git a/src/index.js b/src/index.js index fe1e7b4..c29a799 100644 --- a/src/index.js +++ b/src/index.js @@ -8,7 +8,7 @@ import reactPreset from "babel-preset-react" import flowPreset from "babel-preset-flow" import dynamicImportPlugin from "babel-plugin-syntax-dynamic-import" -import moduleResolverPlugin from "babel-plugin-module-resolver" +import rootImportPlugin from "babel-plugin-module-resolver" import fastAsyncPlugin from "babel-plugin-fast-async" import classPropertiesPlugin from "babel-plugin-transform-class-properties" import objectRestSpreadPlugin from "babel-plugin-transform-object-rest-spread" @@ -36,6 +36,9 @@ export default function buildPreset(context, opts = {}) // Lodash Plugin Settings optimizeModules: [ "lodash", "async", "rambda", "recompose" ], + // + sourceFolder: "src", + // Babel Settings comments: false, compact: true, @@ -104,9 +107,12 @@ export default function buildPreset(context, opts = {}) plugins.push([ lodashPlugin, { id: options.optimizeModules }]) // Supports loading files in source folder without relative folders - // https://github.com/tleunen/babel-plugin-module-resolver - plugins.push([ moduleResolverPlugin, { - root: [ resolvePath(getAppRoot(), "src") ] + // https://github.com/entwicklerstube/babel-plugin-root-import + // It's better than "babel-plugin-module-resolver" as it supports a custom prefix + // so that it is clear which files are locally or from `node_modules`. + plugins.push([ rootImportPlugin, { + rootPathPrefix: "~", + rootPathSuffix: [ resolvePath(getAppRoot(), options.sourceFolder) ] }]) // Alternative to Babel Regenerator