Build 使用网页包';s咖啡加载器,但未明确说明“s”;。“咖啡”;文件扩展名 前言
我目前正在将构建过程从Browserify切换到Webpack。由于项目使用了大量的coffee脚本,我有许多导入语句,例如:Build 使用网页包';s咖啡加载器,但未明确说明“s”;。“咖啡”;文件扩展名 前言,build,webpack,coffeescript,Build,Webpack,Coffeescript,我目前正在将构建过程从Browserify切换到Webpack。由于项目使用了大量的coffee脚本,我有许多导入语句,例如: require('./coffee-file-without-extension') # note the lack of .coffee require('./legacy-js-file-without-extension') # note the lack of .js 问题 Browserify可以很好地处理没有文件扩展名的情况。由于此错误,网页包似乎存在问
require('./coffee-file-without-extension') # note the lack of .coffee
require('./legacy-js-file-without-extension') # note the lack of .js
问题 Browserify可以很好地处理没有文件扩展名的情况。由于此错误,网页包似乎存在问题: 未找到模块:错误:无法解析“/Users/jusopi/Dev/workspace/nx/nx ui/src”中的“/wptest req” 我为此设置了一个超级简单的测试项目,其中包含以下文件: wptest.咖啡
require('./wptest-req')
module.exports = {}
wptest所需咖啡
require('./wptest-req')
module.exports = {}
webpack.config.js
const path = require('path');
const webpack = require('webpack')
module.exports = {
entry: {
main: './src/wptest.coffee'
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist')
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: 'common' // Specify the common bundle's name.
})
],
module: {
rules: [
{
test: /\.coffee$/,
use: [
{
loader: 'coffee-loader',
options: { sourceMap: true }
}
]
}
]
}
};
最终目标
我希望我不必检查我们应用程序中的每个文件,如果可能的话,在咖啡文件的所有require语句中附加
.coffee
虽然此解决方案不是咖啡加载器特有的,但它确实解决了我的问题。我需要在配置中添加一个resolve
对象:
const path = require('path');
const webpack = require('webpack')
module.exports = {
entry: {
main: './src/main.coffee'
// other: './src/index2.js'
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist')
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: 'common' // Specify the common bundle's name.
})
],
module: {
rules: [
{
test: /\.coffee$/,
use: [
{
loader: 'coffee-loader',
options: { sourceMap: true }
}
]
}
]
},
resolve: {
extensions: [ '.coffee', '.js' ]
}
};
src-