question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Skip preserving file extension for generated path

See original GitHub issue

Babel would emit the files with js extension irrespective of the extension of source files, which would cause problem to test individual files without using webpack or gulp, since required modules path would never be resolved, becuase generated files would have an extension of js and the generated webpack alias path would be referring to jsx(i.e original extension)

I’ve shown an example to support the use case

.babelrc

{
  "presets": ["es2015", "react","stage-2"],
  "plugins" : [
  ["babel-plugin-webpack-alias", { "config": "./webpack/server/server.js" }]
  ],
}

webpack config

resolve : {
    extensions: ['','.js','.jsx'],
    modules : [srcPath,path.join(basePath,'./node_modules')],
    alias : {
      template: path.join(srcPath,'./template')
    },
  },

es6 code

import Layout from 'template/Layout';

Generating es5 file post babel transformation

src/server/template/Layout.jsx -> lib/server/template/Layout.js

Post babel transformation

var _Layout = require('./Layout.jsx'); //should be './Layout.js'
var _Layout2 = _interopRequireDefault(_Layout);

Running in node

Error: Cannot find module './Layout.jsx'

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
devarshcommented, Sep 9, 2016

@adriantoine thanks alot, i’ll check and revert back to you

0reactions
adriantoinecommented, Sep 8, 2016

@devarsh It’s just been released in v2.1.0!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get the filename without the extension in Java?
The removeExtension method preserves the rest of the path along with the filename. ... Remove the file extension from a filename, that may...
Read more >
How can I recursively copy files by file extension, preserving ...
At the Linux command line, I'd like to copy a (very large) set of .txt files from one directory (and its subdirectories) to...
Read more >
SharePoint Migration Tool settings - Microsoft 365
Enter a list of file extensions of file types you do not want to migrate. Separate each extension entered with a colon. Do...
Read more >
Ignoring Code - Prettier
Use .prettierignore to ignore (i.e. not reformat) certain files and folders completely. Use “prettier-ignore” comments to ignore parts of files.
Read more >
cp - Copy specific file type keeping the folder structure
c would be created on the remote machine, preserving its full path. These extra path elements are called "implied directories" (i.e. the "foo" ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found