当需要react-bootstrap-typeahead

时间:2016-05-05 18:44:49

标签: javascript css reactjs browserify grunt-browserify

我正在尝试将https://www.npmjs.com/package/react-bootstrap-typeahead包含在我的项目中,但是当我运行我的grunt browserify任务时,出现ParseError: Unexpected token错误。完整信息:

Running "browserify:dist" (browserify) task
>> /path/to/project/node_modules/react-bootstrap-typeahead/css/Typeahead.css:1
>> .bootstrap-typeahead .dropdown-menu {
>> ^
>> ParseError: Unexpected token
Warning: Error running grunt-browserify. Use --force to continue.

Aborted due to warnings.

问题是react-bootstrap-typeahead源js中有require('/some/file.css')

这是我的grunt browserify任务:

    browserify: {
        dist: {
            cwd: 'build',
            options: {
                transform : ['browserify-css'],
                alias: {
                    'index' : './dist/index.js',
                    'root' : './dist/containers/root.js',
                    'designs' : './dist/components/designs.js',
                    'addMutationForm' : './dist/components/addMutationForm.js',
                    'ProteinChecker': './dist/containers/ProteinChecker.js',
                    'configureStore': './dist/configureStore.js',
                    'actions' : './dist/actions.js',
                    'reducers' : './dist/reducers.js',
                    'utils': './dist/utils.js',
                },
                require: [
                    './node_modules/isomorphic-fetch',
                    './node_modules/jquery',
                    './node_modules/react',
                    './node_modules/react-dom',
                    './node_modules/bootstrap',
                    './node_modules/redux',
                    './node_modules/babel-polyfill',
                    './node_modules/redux-logger',
                    './node_modules/redux-thunk',
                    './node_modules/underscore',
                    './node_modules/redux-form',
                    './node_modules/react-bootstrap-typeahead'
                ]
            },
            src: ['./dist/*.js', './dist/*/*.js'],
            dest: './public/build/app.js'
        }
    }

我在尝试解决问题时遇到的一些事情: 一个类似SO(但尚未回答)的问题,但使用webpack,而不是grunt + browserify所以我认为不适用: Using react-bootstrap-typeahead generating CSS errors 在react-bootstrap-typeahead项目的github页面上有一个已关闭的问题,但没有解决通过grunt使用的问题: https://github.com/ericgio/react-bootstrap-typeahead/issues/2 建议使用browserify-css转换。

我试图通过在选项字段中添加transform : ['browserify-css']来使用此转换,但这不起作用。我仍然得到完全相同的错误消息。

我尝试在命令行上使用browserify和browserify-css转换来捆绑这一个库,然后包含该捆绑包,但这会导致更多的错误我认为与相对导入有关(我不认为这是一个很好的解决方案,因为如果我理解了浏览器权限,那么最终会包含两次反应,一次是针对我在命令行上制作的typeahead捆绑包,再次针对实际的应用捆绑包然后最后的js文件是巨大的!)。

关于我如何解决这个问题的任何想法?

提前致谢!

1 个答案:

答案 0 :(得分:1)

所以解决方案是添加

"browserify": {
    "transform": ["browserify-css"]
}

到react-bootstrap-typeahead的packages.json。 它出现在browserify-css docs中......(facepalm)

相关问题