我正在嘗試在我的TypeScript應用程序中使用Fuse。我正在使用import * as fuselib from 'fuse.js';
導入模塊類型。這與編號tsc
罰款。我遇到的問題是當我使用webpack --config config/webpack.prod.js --progress --profile --bail
構建項目時。爲什麼當TypeScript編譯器不能找到一個模塊時,Webpack將無法找到一個模塊?
我收到錯誤Cannot find module 'fuse.js'
。 Fuse類型可以找到here。看着我編譯的JS,我找不到字fuse.js
,所以我猜Webpack正在改變這個名字。我試圖忽略UglifyJsPlugin
中的關鍵字fuse.js
,但這並沒有幫助。
我的Webpack配置非常標準。
webpack.prod.js
var webpack = require('webpack');
var webpackMerge = require('webpack-merge');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var commonConfig = require('./webpack.common.js');
var helpers = require('./helpers');
const ENV = process.env.NODE_ENV = process.env.ENV = 'production';
module.exports = webpackMerge(commonConfig, {
devtool: 'source-map',
output: {
path: helpers.root('dist'),
publicPath: '/',
filename: '[name].[hash].js',
chunkFilename: '[id].[hash].chunk.js'
},
htmlLoader: {
minimize: false // workaround for ng2
},
plugins: [
new webpack.NoErrorsPlugin(),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin({ // https://github.com/angular/angular/issues/10618
mangle: {
keep_fnames: true,
except: ['fuse.js']
}
}),
new ExtractTextPlugin('[name].[hash].css'),
new webpack.DefinePlugin({
'process.env': {
'ENV': JSON.stringify(ENV)
}
})
]
});
webpack.common.js
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var helpers = require('./helpers');
module.exports = {
entry: {
'polyfills': './src/polyfills.ts',
'vendor': './src/vendor.ts',
'app': './src/main.ts'
},
resolve: {
extensions: ['', '.js', '.ts', '.tsx'],
modulesDirectories: ['src', 'node_modules']
},
module: {
loaders: [
{
test: /\.ts$/,
loaders: ['awesome-typescript-loader', 'angular2-template-loader', 'angular2-router-loader']
},
{
test: /\.html$/,
loader: 'html'
},
{
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
loader: 'file?name=assets/[name].[hash].[ext]'
},
{
test: /\.css$/,
exclude: helpers.root('src', 'app'),
loader: ExtractTextPlugin.extract('style', 'css?sourceMap')
},
{
test: /\.css$/,
include: helpers.root('src', 'app'),
loader: 'raw'
}
]
},
plugins: [
// for materialize-css
new webpack.ProvidePlugin({
"window.jQuery": "jquery",
"window._": "lodash",
_: "lodash"
}),
new webpack.optimize.CommonsChunkPlugin({
name: ['app', 'vendor', 'polyfills']
}),
new HtmlWebpackPlugin({
template: 'src/index.html'
})
]
};
我是什麼,以便使的WebPack看到模塊fuse.js
失蹤?
您是否將其添加到package.json中並執行npm安裝? –
我做過了,入口是'「fuse.js」:「2.6.1」'。 – onetwothree
另請參閱https://github.com/krisk/Fuse/pull/124,其中描述瞭解決方法。 – Arjan