-
Notifications
You must be signed in to change notification settings - Fork 73
Closed
Description
I'm considering using Svelte 3 as a replacement to JQuery. As an example for myself how that could work, I am trying to implement simple filter (text input that filters elements by name). I want to plant this filter deep inside existing HTML layout (actually, Handlebars layout).
Here's my webpack config:
{
resolve: {
alias: {
App: path.resolve(__dirname, 'app/'),
},
mainFields: ['svelte', 'browser', 'module', 'main'],
},
entry: {
app: './app/app.js',
vendor: ['jquery', 'what-input'],
main: './scss/main.scss',
},
output: {
filename: `./js/[name]-${release_id}.bundle.min.js`,
sourceMapFilename: `./maps/[name]-${release_id}.map`,
},
module: {
rules: [
{
test: /\.svelte$/,
exclude: /node_modules/,
use: {
loader: 'svelte-loader',
options: {
emitCss: false,
hotReload: false, // svelte 3 not yet supported
},
},
},
// Transpire JS to es2015
// Babel required for Foundation6. http://foundation.zurb.com/sites/docs/javascript.html
{
test: /\.js$/,
// exclude: /(node_modules)/,
// Excluding node_modules also excludes processing external dependencies
use: [{
loader: 'babel-loader',
options: {
presets: [
['env', {
targets: {
browsers: browserslist,
},
useBuiltIns: true,
debug: false,
}],
],
},
}],
},
{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
// use: ['css-loader', 'sass-loader']
use: [
{ loader: 'css-loader', options: { sourceMap: true } }, // Load CSS into Webpack
// postcss-loader autoprefixes CSS
// Not sure if needed. Installed based on usage notes here: http://foundation.zurb.com/sites/docs/sass.html
{
loader: 'postcss-loader',
options: {
plugins: () => [
precss,
autoprefixer,
postcssPresetEnv(),
],
},
},
// Compiles Sass to CSS
{
loader: 'sass-loader',
options: {
includePaths: ['node_modules/motion-ui/src'],
sourceMap: true,
outputStyle: 'compact',
},
},
],
}),
},
{
test: /\.(png|woff|woff2|eot|ttf|svg)$/,
use: 'url-loader?limit=100000',
},
],
},
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
}),
new ExtractTextPlugin(`./css/[name]-${release_id}.css`),
],
}
My component file is called diagrams-filter.svelte
and looks as dumb as it could be:
This is a Filter
<script>
console.log('filter fired')
</script>
I import this component like this:
import DiagramsFilter from './diagrams-filter.svelte'
const data = getData()
const filter = new DiagramsFilter({
target: document.querySelector('DiagramsFilter'),
props: {
l: data.l,
l_prefix: data.l_prefix,
diagrams: data.pages,
},
})
And in my Handlebars template I have an element with DiagramsFilter
id:
<div id="DiagramsFilter"></div>
What am I doing wrong? Or maybe I'm trying to do something that is not possible? Or maybe I'm trying to do something that is just not yet supported? Or it is just a bug?
Any advice will be appreciated. Thank you.
Metadata
Metadata
Assignees
Labels
No labels