最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to use noParse in webpack? - Stack Overflow

programmeradmin1浏览0评论

I want to exclude this from my webpack file, by using this line of code given to me below.

noParse: /node_modules\/localforage\/dist\/localforage.js/,

But no matter what I try I it keeps on saying errors like

ReferenceError: Unknown plugin "add-module-exports" specified in C:/..../node_modules\localforage\.babelrc

Here is my webpack config file:

var path = require('path');
 var HtmlWebpackPlugin = require('html-webpack-plugin');

 module.exports = {
   entry: './app/index.js',
   output: {
     path: path.resolve(__dirname, 'dist'),
     filename: 'index_bundle.js',
     publicPath: '/'
   },
   devServer: {
    historyApiFallback: true,
  },
   module: {
     rules: [
       { test: /\.(js)$/, use: 'babel-loader' },

       { test: /\.css$/, use: [ 'style-loader', 'css-loader' ]}
     ]
   },
   plugins: [
     new HtmlWebpackPlugin({
       template: 'app/index.html'
     })
  ]
};

I want to exclude this from my webpack file, by using this line of code given to me below.

noParse: /node_modules\/localforage\/dist\/localforage.js/,

But no matter what I try I it keeps on saying errors like

ReferenceError: Unknown plugin "add-module-exports" specified in C:/..../node_modules\localforage\.babelrc

Here is my webpack config file:

var path = require('path');
 var HtmlWebpackPlugin = require('html-webpack-plugin');

 module.exports = {
   entry: './app/index.js',
   output: {
     path: path.resolve(__dirname, 'dist'),
     filename: 'index_bundle.js',
     publicPath: '/'
   },
   devServer: {
    historyApiFallback: true,
  },
   module: {
     rules: [
       { test: /\.(js)$/, use: 'babel-loader' },

       { test: /\.css$/, use: [ 'style-loader', 'css-loader' ]}
     ]
   },
   plugins: [
     new HtmlWebpackPlugin({
       template: 'app/index.html'
     })
  ]
};
Share Improve this question edited Jul 22, 2017 at 9:31 Dovydas Šopa 2,3008 gold badges28 silver badges34 bronze badges asked Jul 21, 2017 at 18:44 Mr.BanksMr.Banks 4372 gold badges7 silver badges20 bronze badges 4
  • it's not very clear. Where is noParse: /node_modules\/localforage\/dist\/localforage.js/, written? – Stanislav Mayorov Commented Jul 21, 2017 at 20:35
  • well I am not familiar with webpack, I want to exclude node_modules and localforage.js but I dont know where to do it. – Mr.Banks Commented Jul 21, 2017 at 21:15
  • You shouldn't exclude node_modules. why do you want to exclude node_modules folder? – Stanislav Mayorov Commented Jul 21, 2017 at 21:26
  • I dont know why also, but thats what this module is telling me to do for it to work with webpack https://github./localForage/localForage it says Webpack will emit a warning about using a prebuilt javascript file which is fine. If you want to remove the warning you should exclude localforage from being parsed by webpack using the following conf : module: { noParse: /node_modules\/localforage\/dist\/localforage.js/, loaders: [...], I want to be able to use the LocalForage – Mr.Banks Commented Jul 21, 2017 at 21:30
Add a ment  | 

1 Answer 1

Reset to default 0

You can use localForage 1.3+ version with webpack. You should add noParse in your config.

var path = require('path');
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
    entry: './app/index.js',
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'index_bundle.js',
        publicPath: '/'
    },
    devServer: {
        historyApiFallback: true,
    },
    module: {
        noParse: /node_modules\/localforage\/dist\/localforage.js/,
        rules: [{
            test: /\.(js)$/,
            exclude: /localforage/,
            use: 'babel-loader'
        }, {
            test: /\.css$ / ,
            use: ['style-loader', 'css-loader']
        }]
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: 'app/index.html'
        })
    ]
};
发布评论

评论列表(0)

  1. 暂无评论