首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Sass编译器Phoenix框架

Sass编译器Phoenix框架
EN

Stack Overflow用户
提问于 2016-04-25 16:54:46
回答 2查看 343关注 0票数 0

我刚接触前端Phoenix框架,正在尝试实现Sass,但是“priv/static/css/app.css”不是使用“web/static/css/app.scss”编译的。我的app.css.map文件如下所示:

{"version":3,"sources":"web/static/css/app.scss","names":[],"mappings":"","file":"priv/static/css/app.css"}

我的brunch.config文件看起来像这样:

代码语言:javascript
复制
exports.config = {
  // See http://brunch.io/#documentation for docs.
  files: {
    scripts: {
      joinTo: "js/app.js"

      // To use a separate vendor.js bundle, specify two files path
      // https://github.com/brunch/brunch/blob/stable/docs/config.md#files
      // joinTo: {
      //  "js/app.js": /^(web\/static\/js)/,
      //  "js/vendor.js": /^(web\/static\/vendor)|(deps)/
      // }
      //
      // To change the order of concatenation of files, explicitly mention here
      // https://github.com/brunch/brunch/tree/master/docs#concatenation
      // order: {
      //   before: [
      //     "web/static/vendor/js/jquery-2.1.1.js",
      //     "web/static/vendor/js/bootstrap.min.js"
      //   ]
      // }
    },
    stylesheets: {
      joinTo: "css/app.css"
    },
    templates: {
      joinTo: "js/app.js"
    }
  },

  conventions: {
    // This option sets where we should place non-css and non-js assets in.
    // By default, we set this to "/web/static/assets". Files in this directory
    // will be copied to `paths.public`, which is "priv/static" by default.
    assets: /^(web\/static\/assets)/
  },

  // Phoenix paths configuration
  paths: {
    // Dependencies and current project directories to watch
    watched: [
      "web/static",
      "test/static"
    ],

    // Where to compile files to
    public: "priv/static"
  },

  // Configure your plugins
  plugins: {
    babel: {
      // Do not use ES6 compiler in vendor code
      ignore: [/web\/static\/vendor/]
    }
    sass: {
      options: {
        includePaths: ['web/static/vendor/bootstrap-sass/assets/stylesheets']
      }
    }
  },

  modules: {
    autoRequire: {
      "js/app.js": ["web/static/js/app"]
    }
  },

  npm: {
    enabled: true,
    // Whitelist the npm deps to be pulled in as front-end assets.
    // All other deps in package. will be excluded from the bundle.
    whitelist: ["phoenix", "phoenix_html"]
  }
};

当我运行node node_modules/brunch/bin/brunch build时,我也得到一个错误:

代码语言:javascript
复制
25 Apr 09:06:33 - error: Initialization error - SyntaxError: Unexpected identifier
  at exports.runInThisContext (vm.js:53:16)
  at Module._compile (module.js:387:25)
  at Object.Module._extensions..js (module.js:422:10)
  at Module.load (/Users/dara.carolan/Sites/tomcat/node_modules/coffee-script/lib/coffee-script/register.js:45:36)
  at Function.Module._load (module.js:314:12)
  at Module.require (module.js:367:17)
  at require (internal/module.js:20:19)
  at Promise.then.config (/Users/dara.carolan/Sites/tomcat/node_modules/brunch/lib/application.js:458:18)
  at Object.keys.forEach.environments.forEach.Object.keys.map.exports.install.exports.replaceConfigSlashes.Object.keys.forEach.types.map.type.map.joinTo.map.types.forEach.exports.setConfigDefaults.Object.keys.forEach.normalized.paths.possibleConfigFiles.Object.keys.map.readComponents.then.Promise.then.obj.catch (/Users/dara.carolan/Sites/tomcat/node_modules/brunch/lib/application.js:450:10)
  at Object.keys.forEach.environments.forEach.Object.keys.map.exports.install.exports.replaceConfigSlashes.Object.keys.forEach.types.map.type.map.joinTo.map.types.forEach.exports.setConfigDefaults.Object.keys.forEach.normalized.paths.possibleConfigFiles.Object.keys.map.readComponents.then.Promise.then.exports.loadConfig.tryToLoad.then.config.then.then.then.config.then [as loadConfig] (/Users/dara.carolan/Sites/tomcat/node_modules/brunch/lib/application.js:496:10)
  at new BrunchWatcher (/Users/dara.carolan/Sites/tomcat/node_modules/brunch/lib/watch.js:75:17)
  at Promise.all.then.setProp.constructor.application.loadConfig.then.then.initCompilation.initWatcher.chokidar.watch.on.on.absPath.on.compile.assetErrors.forEach.Promise.all.then.then.watch (/Users/dara.carolan/Sites/tomcat/node_modules/brunch/lib/watch.js:341:10)
  at exports.new.start (/Users/dara.carolan/Sites/tomcat/node_modules/brunch/lib/index.js:27:10)
  at Command.listener (/Users/dara.carolan/Sites/tomcat/node_modules/commander/index.js:301:8)
  at emitTwo (events.js:100:13)
  at Command.emit (events.js:185:7)
  at Command.parseArgs (/Users/dara.carolan/Sites/tomcat/node_modules/commander/index.js:615:12)
  at Command.parse (/Users/dara.carolan/Sites/tomcat/node_modules/commander/index.js:458:21)
  at Object.keys.forEach.exports.run (/Users/dara.carolan/Sites/tomcat/node_modules/brunch/lib/cli.js:73:11)
  at loadBrunch (/Users/dara.carolan/Sites/tomcat/node_modules/brunch/bin/brunch:34:7)
  at /Users/dara.carolan/Sites/tomcat/node_modules/brunch/bin/brunch:44:5
  at FSReqWrap.oncomplete (fs.js:82:15)

我是凤凰城的新手,如果我犯了一个愚蠢的错误,我很抱歉,任何建议都会很好,谢谢!

EN

回答 2

Stack Overflow用户

发布于 2016-06-10 14:56:31

可能会检查您的文件/Users/dara.carolan/Sites/tomcat/node_modules/coffee-script/lib/coffee-script/register.js,它似乎是错误的:)

票数 0
EN

Stack Overflow用户

发布于 2019-02-22 12:36:54

Phoenix 1.4中, sass是使用、webpack、实现的,如here所解释的那样。

在您的npm中安装node-sasssass-loader {test: /\.scss$/, use: [ MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader' ]}

  • Rename

  • project

  • Update {test: /\.scss$/, use: [ MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader' ]}

  • Rename app.js to import css from "../css/app.scss"

{test: /\.scss$/, use: [ MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader' ]}

  • Rename app.css to app.scss

  • Update in app.jstoimport css from "../css/app.scss"
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36835905

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档