Webpack bootstrap ExtractTextPlugin SCSS - 模块解析失败意外字符'@'(Webpack bootstrap ExtractTextPlugin SCSS - Module Parse Failed Unexpected character '@')
我正在尝试使用webpack从bootstrap 4.0.0 beta scss输出css文件。 我按照以下内容成功处理了带内联样式注入的scss: https ://getbootstrap.com/docs/4.0/getting-started/webpack/。 存在与将样式注入文档头部相关的问题。
这是我的package.json:
{ "name": "testproject", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "build": "webpack" }, "keywords": [], "author": "", "license": "ISC", "devDependencies": { "@types/knockout": "^3.4.46", "bootstrap": "^4.0.0-beta", "css-loader": "^0.28.7", "extract-text-webpack-plugin": "^3.0.1", "html-webpack-plugin": "^2.30.1", "jquery": "^3.2.1", "knockout": "^3.4.2", "node-sass": "^4.5.3", "popper.js": "^1.12.5", "postcss-loader": "^2.0.8", "precss": "^2.0.0", "sass-loader": "^6.0.6", "style-loader": "^0.19.0", "ts-loader": "^3.0.2", "typescript": "^2.5.3", "url-loader": "^0.6.2", "webpack": "^3.7.1", "webpack-notifier": "^1.5.0" }, "-vs-binding": { "BeforeBuild": [ "build" ] }, "dependencies": {} }
和我的webpack.config.js(更新):
var path = require('path'); var webpack = require('webpack'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const ExtractTextPlugin = require('extract-text-webpack-plugin'); const extractScss = new ExtractTextPlugin({ filename: 'dist/[name].[hash].css', allChunks: true, }); module.exports = { entry: { site: [ './wwwroot/js/site.js', './Script/testkoviewmodel.ts'], }, output: { publicPath: "/dist/", path: path.join(__dirname, '/wwwroot/dist/'), filename: '[name].[hash].build.js', }, plugins: [ extractScss, new webpack.optimize.UglifyJsPlugin({ minimize: true, compress: { warnings: false }, }), new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery', 'window.jQuery': 'jquery', Popper: ['popper.js', 'default'], }), new HtmlWebpackPlugin({ inject: false, template: 'Views/Shared/_LayoutTemplate.cshtml', filename: '../../Views/Shared/_Layout.cshtml', }), ], devtool: 'source-map', module: { rules: [ { test: /\.tsx?$/, loader: 'ts-loader', exclude: /node_modules/, }, { test: /\.css$/, loader: "style-loader!css-loader" }, { test: /\.scss$/, use: extractScss.extract({ fallback: 'style-loader', use: ['css-loader', 'sass-loader'] }), exclude: /node_modules/, }, { test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: "file" }, { test: /\.(woff|woff2)$/, loader: "url?prefix=font/&limit=5000" }, { test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=application/octet-stream" }, { test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=image/svg+xml" }, ] }, resolve: { extensions: ['.ts', '.tsx', '.js', '.scss'], } };
我已尝试对webpack配置进行各种修改,因为很多人都有相同或相关的问题。 到目前为止,我显然没有成功。
**编辑!重要:整个问题是排除属性应该是QUOTED,因为它们不是正则表达式,而是在这种情况下的字符串。 感谢BudHead!
I'm attempting to output a css file from bootstrap 4.0.0 beta scss using webpack. I've successfully handled scss with an inline style injection as per: https://getbootstrap.com/docs/4.0/getting-started/webpack/ . There are issues related to having the style injected into the head of the document.
here's my package.json:
{ "name": "testproject", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "build": "webpack" }, "keywords": [], "author": "", "license": "ISC", "devDependencies": { "@types/knockout": "^3.4.46", "bootstrap": "^4.0.0-beta", "css-loader": "^0.28.7", "extract-text-webpack-plugin": "^3.0.1", "html-webpack-plugin": "^2.30.1", "jquery": "^3.2.1", "knockout": "^3.4.2", "node-sass": "^4.5.3", "popper.js": "^1.12.5", "postcss-loader": "^2.0.8", "precss": "^2.0.0", "sass-loader": "^6.0.6", "style-loader": "^0.19.0", "ts-loader": "^3.0.2", "typescript": "^2.5.3", "url-loader": "^0.6.2", "webpack": "^3.7.1", "webpack-notifier": "^1.5.0" }, "-vs-binding": { "BeforeBuild": [ "build" ] }, "dependencies": {} }
and my webpack.config.js (updated):
var path = require('path'); var webpack = require('webpack'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const ExtractTextPlugin = require('extract-text-webpack-plugin'); const extractScss = new ExtractTextPlugin({ filename: 'dist/[name].[hash].css', allChunks: true, }); module.exports = { entry: { site: [ './wwwroot/js/site.js', './Script/testkoviewmodel.ts'], }, output: { publicPath: "/dist/", path: path.join(__dirname, '/wwwroot/dist/'), filename: '[name].[hash].build.js', }, plugins: [ extractScss, new webpack.optimize.UglifyJsPlugin({ minimize: true, compress: { warnings: false }, }), new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery', 'window.jQuery': 'jquery', Popper: ['popper.js', 'default'], }), new HtmlWebpackPlugin({ inject: false, template: 'Views/Shared/_LayoutTemplate.cshtml', filename: '../../Views/Shared/_Layout.cshtml', }), ], devtool: 'source-map', module: { rules: [ { test: /\.tsx?$/, loader: 'ts-loader', exclude: /node_modules/, }, { test: /\.css$/, loader: "style-loader!css-loader" }, { test: /\.scss$/, use: extractScss.extract({ fallback: 'style-loader', use: ['css-loader', 'sass-loader'] }), exclude: /node_modules/, }, { test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: "file" }, { test: /\.(woff|woff2)$/, loader: "url?prefix=font/&limit=5000" }, { test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=application/octet-stream" }, { test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=image/svg+xml" }, ] }, resolve: { extensions: ['.ts', '.tsx', '.js', '.scss'], } };
I've tried all manner of modifications to the webpack config as per many many posts of people all having the same or related issue. So far I've obviously been unsuccessful.
**EDIT !important : The entire problem is the exclude properties should be QUOTED as they are not regex but strings in this case. Thanks to BudHead!
原文:https://stackoverflow.com/questions/46794417
最满意答案
它是ECMA Script 6.这是ES6规范的HTML版本 。 这是
Array.prototype.find()
的特定部分 。更新 :还有, Array.prototype.find实现的Chromium bug 。
It is ECMA Script 6. Here's an HTML version of the ES6 spec. Here's the specific section for
Array.prototype.find()
.Update: also, the Chromium bug for Array.prototype.find implementation.
相关问答
更多-
find方法对数组中存在的每个元素执行一次回调函数, 直到找到一个回调返回true值的元素。 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find 回调返回仅用于指示当前值是否应该是结果。 这有点像find当前值的回答“是或否”问题。 在你的第二种情况下,2次通过e % 2 === 0你回来了i 。 但是i是0 ,一个假值,所以find跳过并继续。 其他值(9和11)不通过e % ...
-
给定谓词函数时, Array.prototype.find()返回数组中的第一个匹配元素;如果没有匹配,则返回undefined 。 Python有filter()函数 ,它过滤谓词上的iterable,而next()则生成可迭代或可选默认值的第一个元素。 结合这些给你相同的: next(filter(pred, iter), None) 其中pred是可调用的,当元素与搜索条件匹配时返回True 。 演示: >>> iterable = [42, 81, 117] >>> parity_odd = la ...
-
Javascript:替代Array.prototype.find()?(Javascript: Alternative to Array.prototype.find()?)[2023-12-08]
这是MDN的polyfill : if (!Array.prototype.find) { Array.prototype.find = function(predicate) { if (this == null) { throw new TypeError('Array.prototype.find called on null or undefined'); } if (typeof predicate !== 'function') { throw ... -
Array.prototype.find()在异步函数中返回undefined(Array.prototype.find() returns undefined in async function)[2021-05-29]
你错过了一个return 。 谓词(传递给find的函数)在你的情况下返回undefined,所以find算法没有得到“匹配”。 只需添加return : let found_user = response.data.find(acc=>{ //found_user is always undefined return acc.username == user_to_find; }) 如果你不使用花括号,你可以不用它 let found_user = response. ... -
它是ECMA Script 6.这是ES6规范的HTML版本 。 这是Array.prototype.find()的特定部分 。 更新 :还有, Array.prototype.find实现的Chromium bug 。 It is ECMA Script 6. Here's an HTML version of the ES6 spec. Here's the specific section for Array.prototype.find(). Update: also, the Chromium b ...
-
检查Gemfile: group :development, :test do gem 'rspec-rails', '~> 3.0.0.beta' end 在控制台运行bundle install命令: 在rails generate rspec:install 尝试在项目文件夹中的bash: find -name spec_helper.rb 有一个完整的引用Rspec使用与轨道: https : //github.com/rspec/rspec-rails check Gemfile for: ...
-
x >>> 0强制x变成一个整数。 因此,如果list是一个数组,那么length就是它的长度; 但如果.length不存在,或者像{a: 17, length: "Unicorns"}这样的傻事, length将为0 。 x >>> 0 forces x to become an integer. Thus, if list is an array, length shall be its length; but if .length doesn't exist, or is something sill ...
-
您可以创建自己的查找功能,重要的是在匹配元素时中断循环。 var data = [{id: 1, name: 'a'}, {id: 2, name: 'b'}]; function altFind(arr, callback) { for (var i = 0; i < arr.length; i++) { var match = callback(arr[i]); if (match) { return arr[i]; break; } ...
-
PhantomJS可能不支持Array.prototype.find。 在测试帮助文件中添加polyfill,它将解决您的问题。 MDN上的Polyfill PhantomJS likely doesn't support Array.prototype.find. Add in a polyfill in a test helpers file and it will solve your issue. Polyfill on MDN
-
您可以考虑其他方法: 使用模拟对象而不是真实对象。 重构初始化程序并将慢速操作提取到另一个方法 模拟对象当然会带来一系列弊端; 它们会变得陈旧,使测试更加脆弱。 但对于一些不是问题的测试。 重构初始化器是我的最爱。 例如 MyBigObject.new(args) 变 MyBigObject.new(args).setup 或者:load_data或:connect_to_database_on_the_moon或任何需要很长时间的事情。 你得到了照片。 显然这意味着更改您的代码,但我发现通常可以在其他 ...