javascript - 基础 6 + webpack : Cannot make Foundation JS work

标签 javascript webpack zurb-foundation webpack-dev-server

我正在努力使用 webpack 安装 foudation js 6。我有一个“意外的 token 导入”。我认为这应该与babel有关,但我找不到问题出在哪里。

我使用 Foundation-sites 6.4.1

这是我的 webpack.config.js

var webpack = require('webpack')
var ExtractTextPlugin = require('extract-text-webpack-plugin')
var HtmlWebpackPlugin = require('html-webpack-plugin')
var express = require('express')
var path = require('path')

module.exports = {
  module: {
    loaders: [
      { test: /\.json$/, loader: 'json' },
      {
        test: /\.js$/,
        loader: 'babel',
        exclude: /node_modules/,
        include: path.join(__dirname, 'src'),
      },
      { test: /\.scss$/, loader: ExtractTextPlugin.extract('style-loader', 'css!sass') },
      { test: /\.css$/, loader: ExtractTextPlugin.extract('style-loader', 'css-loader') },
      { test: /\.(eot|svg|ttf|woff2?).*$/, loader: 'url?limit=10000' },
      { test: /\.(png|jpg|jpeg).*$/, loader: 'url?limit=10000' },
    ],
  },
  plugins: [
    new ExtractTextPlugin('bundle.[hash].css'),
    new HtmlWebpackPlugin({
     template: 'src/index.html.ejs',
    }),
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: JSON.stringify(process.env.NODE_ENV),
      },
    }),
    new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /fr/),
  ],
  entry: ['./src/index.js', './src/index.scss'],
  output: {
    path: 'build/',
    filename: 'bundle.[hash].js',
  },
  devServer: {
    inline: true,
    stats: {
      chunks: false,
    }
  }
}

在我的 .babelrc 中

{
    "presets": ["es2015", "es2016", "es2017", "stage-0", "react"],
    "plugins": ["transform-async-to-generator", "transform-runtime"]
}

在我的index.html.ejs中

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Title</title>
</head>
<body>
  <div id="app"></div>
</body>
</html>

在我的index.js中,我在文件顶部有这个:

import 'script!jquery'
import 'script!what-input'
import 'script!foundation-sites'

有人有想法吗?

谢谢

最佳答案

entry point of foundation-sites使用 ES 模块(import/export),但您没有将 babel-loader 应用到 node_modules,因此他们不会被改变。您也许可以导入已经转译的版本:

import 'foundation-sites/dist/js/foundation.js'

从 webpack 2 开始就支持 ES 模块。强烈建议升级 webpack。 official migration guide应该可以帮助你。

关于javascript - 基础 6 + webpack : Cannot make Foundation JS work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45276232/

相关文章:

css - 任何熟悉移动可见性和 zurbs 基础的人

javascript - bool 值并不反射(reflect)在 ng-model 的任何地方;使用 Batarang 进行验证并使用 Controller 作为

javascript - 如何在 AWS 上获取凭证?我必须使用 AWS Cognito SDK 还是 AWS SDK?

webpack - css-loader,导出css模块映射

javascript - heroku 没有构建我的 webpack 应用程序

jquery - 使用 Zurb Foundation 以编程方式更改自定义表单下拉列表

ruby-on-rails - 要导入的文件未找到或不可读 : foundation/functions RAILS 4. 1.10

javascript - 复选框 筛选按具有多个类的类显示的 div

javascript - 使用 JavaScript 动态交换显示/隐藏并向 anchor 链接添加事件类?

node.js - 在 Docker-Compose 上运行时找不到模块