我有一个现有的angular1应用,正在尝试实现Web Pack
源代码已修改
和webpack如下所示
所有依赖项都包含在package.json中
关注此帖子
http://matthamil.me/blog/Angular-1-and-Webpack/
import webpack from 'webpack';
module.exports = {
// This creates a source map to make your
// console errors a lot more developer friendly
devtool: 'inline-source-map',
// Webpack will start doing its thing here
entry: {
app: './app/app.js',
vendor: ['angular']
},
// Where Webpack spits the output
output: {
path: __dirname + '/dist',
filename: "[name].js"
},
module: {
// These are Webpack plugins (commonly referred
// to as "loaders" in the Webpack community).
// Babel will compile our ES6 to ES5
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
}
]
}
};
当我运行webpack时,显示以下错误
/home/dl/projects/zd /webpackangular1app/webpack.config.js:1
(function (exports, require, module, __filename, __dirname) { import webpack from 'webpack';
^^^^^^
SyntaxError: Unexpected token import
at NativeCompileCache._moduleCompile (/usr/lib/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:226:18)
请说出如何在webpack.config.js中使用import webpack ,尽管有导入的要求,但还是尝试了许多类似的要求,但是没有运气,请指向参考或提出解决方法
答案 0 :(得分:0)
Node尚不支持ES导入语法,您正在尝试在Webpack配置文件中使用该语法。
Webpack不会通过您定义的加载程序等传递您的配置文件,因此您的配置不会通过Babel。
更改此:
import webpack from 'webpack';
对此:
var webpack = require('webpack')