Skip to content
This repository was archived by the owner on Mar 22, 2019. It is now read-only.
e-cloud edited this page Mar 18, 2016 · 1 revision

How do I use jQuery?

##我如何使用jQuery?

For versions of jQuery greater than or equal to 1.10, you shouldn't need to do anything special: just make sure that webpack can find jQuery and require('jquery') in your modules.

If you're using 1.9 or less, you'll need to explicitly tell jQuery that webpack wants it to expose itself as an AMD module by adding this to your config:

jQuery的版本大于或等于1.10,你应该不需要做什么特别的:只需要确保Webpack可以找到jQuery, 并在自己的模块require('jQuery')

{
    amd: {
        jQuery: true
    }
    ...
}

请参阅 amd configuration option 以获取更多信息.

How do I use CoffeeScript (or other compile-to-js languages)?

我如何使用CoffeeScript(或其他编译成js的语言))

webpack can load altJS languages with special loaders. For example,

webpack 可以使用特定loader(加载器)加载altJS类语言。例如:

require('coffee-loader!mymodule.coffee')

However, you probably don't want to specify a loader and extension every time you require your module. Avoiding that requires two steps: 1) configuring webpack to use a special loader for files of the given language and 2) configuring webpack to find modules written in that language. For CoffeeScript, that looks like this:

但是,您可能不希望在每次引用你的模块时指定加载器和扩展。需要两个步骤避免这问题: 1)配置Webpack对指定语言的文件使用特殊的加载器; 2)配置Webpack来寻找使用该语言编写的模块。

对于CoffeeScript,看起来像这样:

{
    module: {
        loaders: [
            {test: /\.coffee$/, loader: 'coffee-loader'},  // Use the CoffeeScript loader for *.coffee files
            ...
        ],
        ...
    },
    resolve: {
        extensions: ['', '.webpack.js', '.web.js', '.js', '.coffee'],  // Look for *.coffee files when resolving modules
        ...
    },
    ...
}

A few things to note: 有几件事情需要注意:

  • The loaders are not bundled with webpack and must be installed separately.

  • In order to retain the original resolution behavior, your extension array must include the default values (as shown above). See resolve.extensions for more details.

  • 这些加载器没有与webpack捆绑安装,必须单独安装

  • 为了保留原本的解析行为,extensions数组必须包含那些默认值(如上所示)。详情参见 resolve.extensions

How do I integrate Webpack with Rails

如何结合 Webpack 开发 Rails

Justin Gordon has created a detailed document describing how to integrate Webpack with Rails, including ReactJS and ES6, and deployment on Heroku: Fast Rich Client Rails Development With Webpack and the ES6 Transpiler.

Justin Gordon 写了一份详细的文档,描述了如何结合 Webpack 开发 Rails,涉及到 ReactJS、ES6 和 Heroku 上的部署:: Fast Rich Client Rails Development With Webpack and the ES6 Transpiler

Clone this wiki locally