roman01la / webpack-closure-compiler

[DEPRECATED] Google Closure Compiler plugin for Webpack
MIT License
464 stars 25 forks source link

How to use import export with babel without externs #17

Closed primozs closed 7 years ago

primozs commented 7 years ago
// foo.js
export default function getPerson() {
 // some code
}

// app.js
import getPerson from './foo';

// babel makes this
exports.default = getPerson;

// closure compiler makes this
d.default, is not a function

cheers

roman01la commented 7 years ago

Could you show your Webpack config?

primozs commented 7 years ago

I found the solution. This is now working if using webpack2 Important is to set babel modules false.

//.babelrc
{
  "presets": [
    ["es2015", { "modules": false }]
  ],
  "ignore": [
    "/node_modules/"
  ]
}
// webpak config is the same
const path = require('path');
const ClosureCompilerPlugin = require('webpack-closure-compiler');

module.exports = {
  entry: [
    path.join(__dirname, 'app.js')
  ],
  output: {
    path: path.join(__dirname, 'dist'),
    filename: 'app.min.js'
  },
  module: {
    loaders: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loaders: ['babel-loader']
      }
    ]
  },
  plugins: [
    new ClosureCompilerPlugin({
      compiler: {
        language_in: 'ECMASCRIPT6',
        language_out: 'ECMASCRIPT5',
        compilation_level: 'ADVANCED'
      }
    })
  ]
};
roman01la commented 7 years ago

Nice! In Webpack 2 you could try it without Babel, since Closure Compiler transpiles ES6.

thaoms commented 6 years ago

What do use as loader for js when not using babel? Interested as well