I try to include the LayerSwitcher Custom Control with webpack in my project, but I always receive the error that ol.inhereitsis undefined in this line:
ol.inherits(ol.control.LayerSwitcher, ol.control.Control);
https://github.com/Viglino/ol3-ext/blob/ddc2f631348f8b1cfb5d24e8cf83ed13c262411d/dist/ol3-ext.js#L94
I already debugged this in firefox 57 (See screenshot) and I don't know why the method is not found, although the module is initialized/imported.
Is there missing something?
My webpack config is the following:
const path = require('path');
var webpack = require("webpack");
module.exports = {
entry: './index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
libraryTarget: 'var',
library: 'IndexJS'
},
devtool: 'source-map',
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader",
query: {
presets: ['env']
}
}
],
rules: [
{
test: require.resolve("./ol3-ext-1.0.1/dist/ol3-ext.js"),
loader: "imports-loader?$=jquery,ol=ol,ol.control=ol/control"
},
{
test: require.resolve("./ol3-ext-1.0.1/dist/ol3-ext.js"),
loader: "exports-loader?LayerSwitcher=LayerSwitcher,LayerPopup=LayerPopup"
}
]
Related
I'm trying to add autoprefixer to webpack 2.2.1 and having issues seeing the prefixes.
I installed postcss-loader https://github.com/postcss/postcss-loader as this seems to be the listed way to handle postcss in webpack.
I'm currently using scss files which I'm importing into my react files.
example: import styles from '../../styles/header.scss';
This is handled in webpack using sass-loader.
I'm not getting any error with my setup but I'm also not seeing any autopre-fixing going on to my files ? I presume this only needs to be added in development not production ?
Here is my dev setup webpack config.
const path = require('path')
const webpack = require('webpack')
const ROOT_DIR = path.resolve(__dirname, '../app')
module.exports = {
devtool: 'eval',
entry: [
`${ROOT_DIR}/js/index`,
'webpack-hot-middleware/client'
],
output: {
path: path.resolve(__dirname, '../public'),
filename: 'bundle.js',
publicPath: '/public/'
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.DefinePlugin({
"config.ASSET_URL": JSON.stringify(process.env.ASSETS_URL),
"config.GA_TRACKING_ID": JSON.stringify(process.env.GA_TRACKING_ID)
})
],
module: {
loaders: [
{ test: /\.js?$/,
loader: 'babel-loader',
include: path.join(__dirname, '../app'),
exclude: /node_modules/
},
{ test: /\.scss?$/,
include: path.join(__dirname, '../app', 'styles'),
use: [
'style-loader',
'css-loader',
{
loader: 'postcss-loader',
options: { plugins: [
require('autoprefixer')
] }
},
{
loader: 'sass-loader',
options: {
data: "$assetPath: '" + process.env.ASSETS_URL + "';"
}
}
]
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
include : path.join(__dirname, '../app', 'images'),
loader : 'file-loader?limit=30000&name=[name].[ext]'
},
{
test: /\.(ttf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
include : path.join(__dirname, '../app', 'fonts'),
loader: 'file-loader?name=fonts/[name].[ext]'
}
]
}
}
I had a to deal with sometime similar recently. Check if it works if you create a separate postcss.config.js file in the directory of your scss files with this in it
//postcss.config.js
module.exports = {
plugins: [
require('autoprefixer')
]
}
and in your webpack config
{ test: /\.scss?$/,
include: path.join(__dirname, '../app', 'styles'),
use: [
{loader: "style-loader"},
{loader: "css-loader"},
{loader: "postcss-loader"},
{loader: "sass-loader",
options: {
data: "$assetPath: '" + process.env.ASSETS_URL + "';"
}
}
]
},
I am getting the following error - 'Module build failed: Error: Final loader didn't return a Buffer or String' when trying to compile JSX components for server-side rendering using Webpack 2 and ReactJS.NET. I have followed the examples as described here as well as in this example.
My folder structure is similar to the Github example, I have one React component, an index.js file and a server.js file. Here are the contents:
/Content/components/TestComponent.jsx
var React = require('react');
class Test extends React.Component {
getInitialState() {
return { data: this.props.greeting };
}
render() {
return (
<div>
<h1>{this.props.greeting}</h1>
</div>);
}
}
module.exports = Test;
/Content/components/index.js
module.exports = {
Test: require('./TestComponent.jsx')
}
/Content/server.js
var Components = require('expose?Components!./components');
And here is my full webpack.config.js:
var path = require('path');
var webpack = require('webpack');
module.exports = {
entry: './Content/server',
output: {
path: __dirname + '/resources/dev/scripts/server',
filename: 'test.js'
},
module: {
rules: [
{
test: /\.js$|.jsx$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['env', 'react'],
}
}
{
test: require.resolve('react'),
loader: 'expose?React'
}
]
},
resolve: {
extensions: ['.js', '.jsx']
},
externals: {
react: 'React'
}
}
I have created an example project here with the same problem.
The solution was to do away with the /Content/server.js file, and instead use the expose-loader in webpack. Here is the updated webpack.config.js:
var path = require('path');
var webpack = require('webpack');
module.exports = {
entry: './Content/components/index',
output: {
path: __dirname + '/resources/dev/scripts/server',
filename: 'test.js'
},
module: {
rules: [
{
test: /\.js$|.jsx$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['env', 'react'],
}
},
{
test: require.resolve('./Content/components/index'),
use: [{
loader: 'expose-loader',
options: 'Components'
}]
},
{
test: require.resolve('react'),
use: [{
loader: 'expose-loader',
options: 'React'
}]
}
]
},
resolve: {
extensions: ['.js', '.jsx']
}
}
I try to run our ASP.NET MVC project with webpack2. As the first step, I set up webpack2 with ExtractTextPlugin.
When running webpack watch, I can see that the bundled css file gets updated.
But if I run the project with IISExpress and with webpack watch running, the browser just won't pickup the latest change even though the file has changed.
Verified that if I turn off webpack watch and refresh the browser, then I can see those changes in the browser.
I am running without webpack dev server, here is the webpack.config.js:
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const path = require('path');
module.exports = env => {
return {
entry: {
"main": "./static/entry.js",
"component": path.resolve(__dirname, "../component/static/bundle.js")
},
output: {
path: path.resolve(__dirname, "./static/dist/scripts"),
filename: "[name].index.js"
},
module: {
rules: [
{
test: /\.scss$/,
exclude: /node_modules/,
use:ExtractTextPlugin.extract({
fallback: "style-loader",
use: [
{
loader: 'css-loader',
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
includePaths: [
path.resolve(__dirname, './default.css'),
path.resolve(__dirname, './normalize.css')
]
}
}
]
})
},
{ test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/ },
{ test: /\.ts$/, loader: 'babel-loader', exclude: /node_modules/ }
]
},
plugins: [
new webpack.ProvidePlugin({
$: path.resolve(__dirname, './node_modules/jquery/src/jquery'),
jQuery: path.resolve(__dirname, './node_modules/jquery/src/jquery'),
moment: path.resolve(__dirname, './node_modules/moment/moment')
}),
new ExtractTextPlugin({
filename: "../style/[name].style.css",
allChunks: true
}),
new webpack.optimize.UglifyJsPlugin({
minimize: true,
compress: {
warnings: false
}
})
]
}
};
The issue is constant and I have no idea what could have happened, help please.
I found the cause of this problem.
Project web.config is caching the client resources, disable output caching fixed the issue.
<caching>
<outputCache enableOutputCache="false" />
</caching>
Im trying to figure out why a css segment will not run through 'style-ext-html-webpack-plugin'.
Currently I have a .CSS file with rules for the splash screen.
It's being extracted using 'extract-text-webpack-plugin' and injected to the template's <head> with 'extract-text-webpack-plugin'.
problem is, the file never gets run through 'style-ext-html-webpack-plugin' and I can't wrap my head around how to debug it.
(Ideally, I'd like to have a .SCSS file so it can be themeable through a .env file. i.e: have splash.scss exclusively extracted and inlined in the <head> after being injected with some theme colors)
webpack.config.js:
....
const ExtractTextPlugin = require('extract-text-webpack-plugin'); //used for above-the-fold css (such as splash-screen)
const StyleExtHtmlPlugin = require('style-ext-html-webpack-plugin');
const extractSplashCSS = new ExtractTextPlugin('splash.css');
module.exports = {
entry: {...},
output: {...},
resolve: {...},
plugins: [
...,
new HtmlWebpackPlugin({
title: enviroments.TITLE,
splashScreenTitle: enviroments.SPLASH_SCREEN_TITLE,
template: 'src/index.html',
cache: true,
favicon: enviroments.FAVICON || './src/assets/images/favicon.ico',
inject: 'body'
}),
extractSplashCSS,
new StyleExtHtmlPlugin('splash.css')
],
module: {
loaders: [
{ test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/ },
{
test: /\.css$/,
loader: 'style-loader!css-loader!resolve-url-loader?import=false',
exclude: [path.join(path.resolve('./src'), 'common/app/splash.css')]
},
{
test: /\.css$/,
loader: extractSplashCSS.extract({
use: 'css-loader'
}),
include: [path.join(path.resolve('./src'), 'common/app/splash.css')]
},
{
test: /\.scss$/,
use: [
'style-loader',
'css-loader?importLoaders=1',
{
loader: 'postcss-loader',
options: {
plugins: function() {
return [require('autoprefixer')];
}
}
},
'resolve-url-loader?sourceMap',
{
loader: 'sass-loader?sourceMap',
options: {
includePaths: path.resolve('./src'),
data: `
$color-primary: ${theme.PRIMARY};
....
`
}
}
]
},
....
]
}
};
index.js:
...
// above the fold css
import 'common/app/splash.css';
Needed to update html-webpack-plugin to 2.29.0.
I've managed to solve this issue, using a sass file that can be themeable with variables from .env file:
I had to explicitly exclude the splash file from the normal sass flow and create another loader definition explicitly for it:
...
const ExtractTextPlugin = require('extract-text-webpack-plugin'); //used for above-the-fold css (such as splash-screen)
const StyleExtHtmlWebpackPlugin = require('style-ext-html-webpack-plugin');
module.exports = {
...
plugins: [
...
new HtmlWebpackPlugin({
...
}),
new ExtractTextPlugin('splash.css'),
new StyleExtHtmlWebpackPlugin('splash.css'),
],
module: {
loaders: [
{ test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/ },
{ test: /\.css$/, loader: 'style-loader!css-loader!resolve-url-loader?import=false' },
{
test: /\.scss$/,
exclude: [path.join(path.resolve('./src'), 'common/app/splash.scss')],
use: [
.....
]
},
{
test: /\.scss$/,
include: [path.join(path.resolve('./src'), 'common/app/splash.scss')],
use: ExtractTextPlugin.extract({
use: [
{
loader: 'css-loader',
options: {minimize: true}
},
{
loader: 'postcss-loader',
options: {
plugins: function() {
return [require('autoprefixer')];
}
}
},
{
loader: 'sass-loader',
options: { data: `$color-primary: ${theme.PRIMARY};` }
}
]
})
},
]
}
};
I've just upgraded to the latest WebPack and my existing configuration throws up an error, I have tracked down which code causes the issue, but not sure how to resolve it.
I have tracked the error down to here
{
test: /\.(css|scss)$/,
loaders: ExtractTextPlugin.extract({
fallbackLoader: 'style',
loader: 'css?minimize!sass!postcss'
})
},
Entries from Package.json
"webpack": "2.2.1",
"extract-text-webpack-plugin": "^2.0.0-beta.3",
"html-webpack-plugin": "^2.24.1",
Error
ERROR in ./~/css-loader?minimize!./~/sass-loader/lib/loader.js!./~/postcss-loader!./src/index.scss
Module build failed: No input specified: provide a file name or a source string to process
# ./src/index.scss 4:14-172
# ./src/main.ts
ERROR in ./src/index.scss
Module build failed: ModuleBuildError: Module build failed: No input specified: provide a file name or a source string to process
at d:\workible\data-extractor\app-client\node_modules\webpack\lib\NormalModule.js:137:35
at d:\workible\data-extractor\app-client\node_modules\loader-runner\lib\LoaderRunner.js:364:11
at d:\workible\data-extractor\app-client\node_modules\loader-runner\lib\LoaderRunner.js:230:18
at context.callback (d:\workible\data-extractor\app-client\node_modules\loader-runner\lib\LoaderRunner.js:111:13)
at Object.asyncSassJobQueue.push [as callback] (d:\workible\data-extractor\app-client\node_modules\sass-loader\lib\loader.js:51:13)
at d:\workible\data-extractor\app-client\node_modules\sass-loader\node_modules\async\dist\async.js:2234:31
at apply (d:\workible\data-extractor\app-client\node_modules\sass-loader\node_modules\async\dist\async.js:20:25)
at d:\workible\data-extractor\app-client\node_modules\sass-loader\node_modules\async\dist\async.js:56:12
at d:\workible\data-extractor\app-client\node_modules\sass-loader\node_modules\async\dist\async.js:840:16
at module.exports.render (d:\workible\data-extractor\app-client\node_modules\node-sass\lib\index.js:375:5)
at d:\workible\data-extractor\app-client\node_modules\sass-loader\node_modules\async\dist\async.js:3894:5
at process (d:\workible\data-extractor\app-client\node_modules\sass-loader\node_modules\async\dist\async.js:2299:17)
at Immediate.<anonymous> (d:\workible\data-extractor\app-client\node_modules\sass-loader\node_modules\async\dist\async.js:2112:16)
at runCallback (timers.js:649:20)
at tryOnImmediate (timers.js:622:5)
at processImmediate [as _immediateCallback] (timers.js:594:5)
ERROR in d:\workible\data-extractor\app-client\node_modules\extract-text-webpack-plugin\loader.js!d:\workible\data-extractor\app-client\node_modules\style-loader\index.js!d:\workible\data-extractor\app-client\node_modules\css-loader\index.js?minimize!d:\workible\data-extractor\app-client\node_modules\sass-loader\lib\loader.js!d:\workible\data-extractor\app-client\node_modules\postcss-loader\index.js!d:\workible\data-extractor\app-client\src\index.scss doesn't export content
WebPack Configuration
const webpack = require('webpack');
const conf = require('./gulp.conf');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const autoprefixer = require('autoprefixer');
module.exports = {
module: {
loaders: [
{
test: /.json$/,
loaders: [
'json'
]
},
{
test: /\.(css|scss)$/,
loaders: ExtractTextPlugin.extract({
fallbackLoader: 'style',
loader: 'css?minimize!sass!postcss'
})
},
{
test: /\.ts$/,
exclude: /node_modules/,
loaders: [
'ts'
]
},
{
test: /.html$/,
loaders: [
'html'
]
}
]
},
plugins: [
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.NoErrorsPlugin(),
new HtmlWebpackPlugin({
template: conf.path.src('index.html')
}),
new webpack.ContextReplacementPlugin(
/angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
conf.paths.src
),
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"'
}),
new webpack.optimize.UglifyJsPlugin({
compress: {unused: true, dead_code: true, warnings: false} // eslint-disable-line camelcase
}),
new ExtractTextPlugin('query-[contenthash].css'),
new webpack.optimize.CommonsChunkPlugin({name: 'vendor'})
],
postcss: () => [autoprefixer],
output: {
path: path.join(process.cwd(), conf.paths.dist),
filename: '[name]-[hash].js'
},
resolve: {
extensions: [
'',
'.webpack.js',
'.web.js',
'.js',
'.ts'
]
},
entry: `./${conf.path.src('main')}`,
ts: {
configFileName: 'tsconfig.json'
},
tslint: {
configuration: require('../tslint.json')
}
};
Added Some CSS to my .scss file as per #ickiir
body {}
Now the Error has advanced to
ERROR in ./src/index.scss
Module build failed: ReferenceError: window is not defined
at d:\workible\data-extractor\app-client\node_modules\style-loader\index.js!d:\workible\data-extractor\app-client\node_modules\css-loader\index.js?minimize!d:\workible\data-extractor\app-client\node_modules\sass-loader\lib\loader.js!d:\workible\data-extractor\app-client\node_modules\postcss-loader\index.js!d:\workible\data-extractor\app-client\src\index.scss:99:30
at d:\workible\data-extractor\app-client\node_modules\style-loader\index.js!d:\workible\data-extractor\app-client\node_modules\css-loader\index.js?minimize!d:\workible\data-extractor\app-client\node_modules\sass-loader\lib\loader.js!d:\workible\data-extractor\app-client\node_modules\postcss-loader\index.js!d:\workible\data-extractor\app-client\src\index.scss:94:47
at module.exports (d:\workible\data-extractor\app-client\node_modules\style-loader\index.js!d:\workible\data-extractor\app-client\node_modules\css-loader\index.js?minimize!d:\workible\data-extractor\app-client\node_modules\sass-loader\lib\loader.js!d:\workible\data-extractor\app-client\node_modules\postcss-loader\index.js!d:\workible\data-extractor\app-client\src\index.scss:116:68)
at Object.<anonymous> (d:\workible\data-extractor\app-client\node_modules\style-loader\index.js!d:\workible\data-extractor\app-client\node_modules\css-loader\index.js?minimize!d:\workible\data-extractor\app-client\node_modules\sass-loader\lib\loader.js!d:\workible\data-extractor\app-client\node_modules\postcss-loader\index.js!d:\workible\data-extractor\app-client\src\index.scss:400:36)
at __webpack_require__ (d:\workible\data-extractor\app-client\node_modules\style-loader\index.js!d:\workible\data-extractor\app-client\node_modules\css-loader\index.js?minimize!d:\workible\data-extractor\app-client\node_modules\sass-loader\lib\loader.js!d:\workible\data-extractor\app-client\node_modules\postcss-loader\index.js!d:\workible\data-extractor\app-client\src\index.scss:21:30)
at d:\workible\data-extractor\app-client\node_modules\style-loader\index.js!d:\workible\data-extractor\app-client\node_modules\css-loader\index.js?minimize!d:\workible\data-extractor\app-client\node_modules\sass-loader\lib\loader.js!d:\workible\data-extractor\app-client\node_modules\postcss-loader\index.js!d:\workible\data-extractor\app-client\src\index.scss:65:18
at Object.<anonymous> (d:\workible\data-extractor\app-client\node_modules\style-loader\index.js!d:\workible\data-extractor\app-client\node_modules\css-loader\index.js?minimize!d:\workible\data-extractor\app-client\node_modules\sass-loader\lib\loader.js!d:\workible\data-extractor\app-client\node_modules\postcss-loader\index.js!d:\workible\data-extractor\app-client\src\index.scss:68:10)
at Module._compile (module.js:570:32)
at Object.exec (d:\workible\data-extractor\app-client\node_modules\webpack\lib\NormalModule.js:94:6)
at Object.<anonymous> (d:\workible\data-extractor\app-client\node_modules\extract-text-webpack-plugin\loader.js:112:21)
at Compiler.<anonymous> (d:\workible\data-extractor\app-client\node_modules\webpack\lib\Compiler.js:251:10)
at d:\workible\data-extractor\app-client\node_modules\webpack\lib\Compiler.js:442:12
at next (d:\workible\data-extractor\app-client\node_modules\tapable\lib\Tapable.js:138:11)
at Compiler.<anonymous> (d:\workible\data-extractor\app-client\node_modules\extract-text-webpack-plugin\loader.js:93:4)
at next (d:\workible\data-extractor\app-client\node_modules\tapable\lib\Tapable.js:140:14)
at Compiler.<anonymous> (d:\workible\data-extractor\app-client\node_modules\ts-loader\dist\after-compile.js:11:13)
ERROR in d:\workible\data-extractor\app-client\node_modules\extract-text-webpack-plugin\loader.js!d:\workible\data-extractor\app-client\node_modules\style-loader\index.js!d:\workible\data-extractor\app-client\node_modules\css-loader\index.js?minimize!d:\workible\data-extractor\app-client\node_modules\sass-loader\lib\loader.js!d:\workible\data-extractor\app-client\node_modules\postcss-loader\index.js!d:\workible\data-extractor\app-client\src\index.scss doesn't export content
I finally resolved this issue by doing the following.
I made sure that my index.scss file was not empty by adding the following (as per #ickyrr)
body {}
And I removed the fallbackLoader
{
test: /\.(css|scss)$/,
loaders: ExtractTextPlugin.extract({
//fallbackLoader: 'style',
loader: 'css?minimize!sass!postcss'
})
},
As of webpack version 2.2.1 there is a syntax change... so instead of using loader or loaders the correct syntax would be 'use'
here is an example:
BEFORE:
{
test: /\.(scss|sass)$/,
include: helpers.root('src/app'),
exclude: [/\.global\.(scss|sass)$/, 'src'],
loaders: ['raw-loader?sourceMap', 'sass-loader?sourceMap']
},
AFTER:
{
test: /\.(scss|sass)$/,
include: helpers.root('src/app'),
exclude: [/\.global\.(scss|sass)$/, 'src'],
use: ['raw-loader?sourceMap', 'sass-loader?sourceMap']
},
Webpack 2 is sooo complicated. After messing around with it for an hour, the following works for me for scss.
{
test:/\.scss$/,
use:ExtractTextPlugin.extract({fallback:"style-loader",use:["css-loader","sass-loader"]}),
include:path.join(__dirname,"client/src"),
},
I reviewed many code samples before I tried the above. Hope this helps.