Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comment that babel-inline-import-loader relies on is not generated #11

Open
jimsimon opened this issue Aug 10, 2017 · 1 comment
Open

Comments

@jimsimon
Copy link

I have BABEL_DISABLE_CACHE=1 set and I've tried setting cacheDirectory: false and neither option helps (as expected since the comment is missing from the output).

.babelrc contents:

{
  "presets": [
    [
      "env", {
      "targets": {
        "browsers": [
          "last 2 Chrome versions"
        ]
      },
      "modules": "umd"
    }]
  ],
  "plugins": [
    [
      "babel-plugin-inline-import", {
        "extensions": [
          ".css"
        ]
      }
    ],
    [
      "transform-incremental-dom", {
        "moduleSource": "incremental-dom"
      }
    ],
    ["transform-class-properties"]
  ],
  "env": {
    "test": {
      "plugins": [
        ["istanbul", {
          "exclude": [
            "tests/**/*"
          ]
        }]
      ]
    },
    "production": {
      "presets": ["babili"]
    }
  }
}

webpack.config.js:

const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
  entry: './docs/index.js',
  devtool: 'inline-source-map',
  output: {
    path: __dirname + '/docs/generated',
    filename: 'docs.js'
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: [
          'babel-inline-import-loader',
          'babel-loader'
        ]
      }
    ]
  },
  plugins: [
    new HtmlWebpackPlugin({
      filename: 'index.html',
      template: 'docs/template.html'
    })
  ]
}

input code:

import Component from '../../component'
import styles from './styles.css'

customElements.define('wc-button', class WcButton extends Component {
  renderCss () {
    super.renderCss()
    return (
      <style>
        {styles}
      </style>
    )
  }

  render () {
    return <button><slot /></button>
  }
})

relevant output:

  const styles = 'button {\n  background: red;\n}\n';

  customElements.define('wc-button', class WcButton extends _component2.default {
    renderCss() {
      super.renderCss();
      (0, _incrementalDom.elementOpen)('style');

      _renderArbitrary(styles);

      return (0, _incrementalDom.elementClose)('style');
    }

    render() {
      (0, _incrementalDom.elementOpen)('button');
      (0, _incrementalDom.elementVoid)('slot');
      return (0, _incrementalDom.elementClose)('button');
    }
  });
@jimsimon
Copy link
Author

After some more research, it seems that setting modules: false instead of modules: "umd" fixes the issue. I tried it with the other possible values for modules and it only seems to work correctly for commonjs and false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant