1

我在同构 javascript 配置中的 webpack 配置有问题,如果我在其中运行:

BROWSER=false NODE_PATH=$NODE_PATH:./shared node --harmony . & webpack-dev-server --progress --color

抛出的错误:

 /node_modules/babel/node_modules/babel-core/lib/transformation/file/index.js:671
      throw err;
            ^
SyntaxError: /Users/allen/NodeJS/node-analytics-frontend/shared/containers/EventConfig.scss: Unexpected token (1:0)
> 1 | .blue {
    | ^
  2 |   color: blue;
  3 | }

这是我的 webpack 配置:

var path = require('path');
var webpack = require('webpack');

module.exports = {
  entry: [
    'webpack-dev-server/client?http://localhost:8080/',
    'webpack/hot/only-dev-server',
    './client'
  ],
  output: {
    path: path.join(__dirname, 'dist'),
    filename: 'bundle.js'
  },
  resolve: {
    modulesDirectories: ['node_modules', 'shared'],
    extensions: ['', '.js', '.jsx']
  },
  module: {
    loaders: [{
      test: /\.scss$/,
      loaders: ['style', 'css', 'sass']
    }, {
      test: /\.jsx?$/,
      exclude: /node_modules/,
      loaders: ['react-hot', 'babel'],
      query: {
        stage: 0
      }
    }]
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoErrorsPlugin(),
    new webpack.DefinePlugin({
      "process.env": {
        BROWSER: JSON.stringify(true)
      }
    })
  ],
  devtool: 'inline-source-map',
  devServer: {
    hot: true,
    proxy: {
      '*': 'http://localhost:' + (process.env.PORT || 3000)
    }
  }
};

我打电话给要求

import styles from './EventConfig.scss';
4

1 回答 1

1

我发现了一个类似的问题babel-core,它可能与环境变量有关。BROWSER=open运行$ env命令时检查是否有。

如果是这样,请通过直接在您的 shell 中设置此变量来尝试其他一些选项——或者您可以在您的.bash_profile.

以下是关于显然已解决的问题的一些讨论: https ://github.com/iam4x/isomorphic-flux-boilerplate/issues/16

我希望这有帮助!

于 2015-09-22T19:08:59.073 回答